본문 바로가기
728x90
반응형

프로그래머스 코테15

c++(cpp) 프로그래머스 - 코딩테스트 : k번째 수 #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; for(int i = 0 ; i < commands.size() ; i++) { vector temp; for(int j = commands[i][0]-1 ; j < commands[i][1]; j ++) { temp.push_back(array[j]); } sort(temp.begin(), temp.end()); answer.push_back(temp[commands[i][2]-1]); } return answer; } 2023. 1. 23.
c++(cpp) 프로그래머스 - 코딩테스트 : [1차]비밀지도 다른 사람들의 코드를 보니까 비트 연산자 이용해서 풀던데.. 그 방법을 애초에 생각하지 못해서 다른 방법으로 풀었다 #include #include #include using namespace std; vector solution(int n, vector arr1, vector arr2) { vector answer; string temp; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < n ; j++) { if(arr1[i] % 2 == 0 && arr2[i] % 2 == 0) { temp += " "; } else { temp += "#"; } arr1[i] /= 2; arr2[i] /= 2; } reverse(temp.begin(), temp.end());.. 2022. 8. 11.
c++(cpp) 프로그래머스 - 코딩 테스트 : 숫자 문자열과 영단어 #include #include using namespace std; string Word[] = {"zero", "one", "two", "three", "four" ,"five", "six", "seven", "eight", "nine"}; int solution(string s) { string result; for(int pos = 0 ; pos = '0' && s[pos] 2022. 7. 28.
c++(cpp) 프로그래머스 - 코딩 테스트 : 2016년 #include #include using namespace std; string solution(int a, int b) { string answer = ""; string week[7] = {"FRI", "SAT","SUN", "MON", "TUE", "WED", "THU"}; int month[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int sum=0; for(int i = 0; i < a; i++) { sum += month[i]; } sum += b-1; answer = week[sum%7]; return answer; } 2022. 7. 28.
c++(cpp) 프로그래머스 - 코딩 테스트 : 핸드폰 번호 가리기 #include #include using namespace std; string solution(string phone_number) { string answer = ""; for(int i = 0 ; i < phone_number.size() - 4 ; i++) { answer += '*'; } for(int j = phone_number.size() - 4 ; j < phone_number.size(); j++) { answer += phone_number[j]; } return answer; } 2022. 7. 28.
c++(cpp) 프로그래머스 - 코딩 테스트 : 하샤드 수 #include #include using namespace std; bool solution(int x) { bool answer = true; int x1 = x; int result=0; while(x > 0) { result += x % 10; x = x / 10 ; } if(x1 % result != 0) { answer = false; } else answer = true; return answer; } 2022. 7. 28.
c++(cpp) 프로그래머스 : 코딩 테스트 - 콜라츠 추측 #include #include using namespace std; int solution(int n) { int answer = 0; long long num = n; while(num != 1) { if(answer < 500) { if(num % 2 == 0) { num = num / 2; answer ++; } else if(num % 2 != 0) { num = num * 3 + 1; answer ++; } } else return -1; } return answer; } 2022. 7. 27.
c++(cpp) 프로그래머스 : 코딩 테스트 - 최대공약수와 최소공배수 #include #include using namespace std; int GCD(int n, int m) { int r; while (m != 0) { r = n % m; n = m; m = r; } return n; } vector solution(int n, int m) { vector answer; answer.push_back(GCD(n,m)); answer.push_back((n*m) / answer[0]); return answer; } 2022. 7. 27.
c++(cpp) 프로그래머스 : 코딩 테스트 - 정수 내림차순으로 배치하기 #include #include #include using namespace std; long long solution(long long n) { long long answer = 0; string temp = to_string(n); sort(temp.begin(), temp.end(), greater()); //string 873211 answer = stoll(temp); return answer; } 2022. 7. 27.
728x90
반응형