본문 바로가기
728x90
반응형
SMALL

분류 전체보기161

[프로그래머스] 문자열 정렬하기 (2) #include #include #include using namespace std; string solution(string my_string) { string answer = ""; for(auto str : my_string){ if(isupper(str)) answer+=tolower(str); else answer+=str; } sort(answer.begin(),answer.end()); return answer; } 2025. 9. 6.
[프로그래머스] 가장 큰 수 찾기 #include #include using namespace std; vector solution(vector array) { vector answer = {0,0}; for(int i=0; i answer = (array[i] > answer[0]) ? vector{array[i],i}:answer; return answer; } 2025. 9. 6.
[프로그래머스] 약수 구하기 #include #include using namespace std; vector solution(int n) { vector answer; for(int i=1; i if(n%i==0) answer.push_back(i); } return answer; } 2025. 9. 6.
[프로그래머스] 인덱스 바꾸기 #include #include using namespace std; string solution(string my_string, int num1, int num2) { string answer = ""; for(int i=0; i { if(i==num1) answer+=my_string[num2]; else if(i==num2) answer+=my_string[num1]; else answer+=my_string[i]; } return answer; } swap() 메소드로 한줄대체 가능swap(my_string[num1],my_string[num2]); 2025. 9. 5.
[프로그래머스] 대문자와 소문자 #include #include #include using namespace std; string solution(string my_string) { string answer = ""; //대->소, 소->대 //대:65~90, 소:97~102 for(char str : my_string){ if(isupper(str)) answer += str+32; else answer += str-32; } return answer; } 2025. 9. 5.
[프로그래머스] 암호 해독 #include #include using namespace std; string solution(string cipher, int code) { string answer = ""; //code의 배수번째만 진짜 암호 for(int i=code; i answer+=cipher[i-1]; return answer; } 2025. 9. 5.
[프로그래머스] 최댓값 만들기 (2) #include #include #include using namespace std; int solution(vector numbers) { int answer = 0; sort(numbers.begin(), numbers.end()); int cmp1 = numbers[0]*numbers[1]; sort(numbers.rbegin(), numbers.rend()); int cmp2 = numbers[0]*numbers[1]; return cmp1 > cmp2? cmp1:cmp2; } 2025. 9. 5.
[프로그래머스] 숨어있는 숫자의 덧셈 (1) #include #include using namespace std; int solution(string my_string) { int answer = 0; for(char str : my_string){ if(str >= '1' && str answer+=(int)str-'0'; } return answer; } 2025. 9. 5.
[프로그래머스] 문자열 정렬하기 (1) #include #include #include using namespace std; vector solution(string my_string) { vector answer; for(char str : my_string){ if(str >= '0' && str answer.push_back(int(str)-'0'); } sort(answer.begin(),answer.end()); return answer; } 2025. 9. 5.
728x90
반응형
LIST