0단계16 [프로그래머스][C++] 홀짝 구분하기 #include using namespace std; int main(void) { int n; cin >> n; cout 2023. 10. 19. [프로그래머스][C++] 문자열 돌리기 #include #include using namespace std; int main(void) { string str; cin >> str; for(int i = 0; i < str.size(); i++) { cout 2023. 10. 19. [프로그래머스][C++] 조건에 맞게 수열 변환하기 2 #include #include #include using namespace std; int solution(vector arr) { int x = 0; while(true) { vector prevArr = arr; // 이전 배열 for(int i = 0; i = 50 && arr[i] % 2 == 0) { // 50보다 크거나 같고, 짝수인 경우 arr[i] /= 2; } else if(arr[i] < 50 && arr[i] % 2 == 1) { // 50보다 작고, 홀수인 경우 arr[i] = arr[i] * 2 + 1; } } // 정렬 sort(prevArr.begin(), prevArr.end()); sort(arr.begin(), a.. 2023. 10. 18. [프로그래머스][C++] 접미사인지 확인하기 #include #include using namespace std; int solution(string my_string, string is_suffix) { int answer = 1; for(int i = 0; i < is_suffix.size() ; i++) { if(my_string[my_string.size() - 1 - i] != is_suffix[is_suffix.size() - 1 - i]) return 0; } return answer; } 1. 0부터 is_suffix의 크기만큼 반복을 진행 2. 문자열 my_string와 is_suffix의 마지막원소부터 하나씩 앞으로 나가면서 비교를 진행 3. 비교하는 중에 하나라도 틀리다면 0을 리턴 4. 반복문을 빠져나왔다면 is_suffix의.. 2023. 10. 13. 이전 1 2 다음