본문 바로가기
프로그래머스코딩테스트연습풀이/C++

[프로그래머스/C++] 문자열 정렬하기 (2)

by 코코쵸마 2025. 2. 21.

문제

영어 대소문자로 이루어진 문자열 my_string이 매개변수로 주어질 때, my_string을 모두 소문자로 바꾸고 알파벳 순서대로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요.

 

솔루션

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string solution(string my_string) {
    string answer = "";
    for(auto c:my_string){
        answer += tolower(c);
    }
    sort(answer.begin(), answer.end());
    return answer;
}

 

https://school.programmers.co.kr/learn/courses/30/lessons/120911