https://school.programmers.co.kr/learn/courses/30/lessons/120911
아스키코드에서 가장 높은숫자의 대문자인 Z의 값 90으로 비교해서 대문자이면 +32(하면 소문자) 해서 소문자로 만들고 그 후 정렬
90말고 'Z' 로 쓰고 +32 말고 'a' - 'A' 값으로 해도된다. 아스키코드를 외우고 다닐 수는 없다고 생각한다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string my_string) {
string answer = "";
for(int i=0;i<my_string.size();i++)
if(my_string[i] <= 90)
my_string[i]+= 32;
sort(my_string.begin(),my_string.end());
answer = my_string;
return answer;
}
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string my_string) {
string answer = "";
transform(my_string.begin(),my_string.end(),my_string.begin(),::tolower);
sort(my_string.begin(),my_string.end());
return my_string;
}
일단 tolower, toupper ( 대문자를 소문자로, 소문자를 대문자로 바꿔주는 함수 )
를 이용하는데 transform(algorithm헤더에 포함)을 사용하여 일괄 변환해준다.