프로그래머스 레벨 1 테스트

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
bool Sort(int a, int b)
{
    return a > b; //내림차순 정렬
//return a < b; //오름차순 정렬
}    
 
string solution(string s) 
{
    sort(s.begin(), s.end(), Sort);
    
    return s;
}
 

 

문자열을 아스키 코드로 변환하면 대문자 A는 '65' 소문자 a는 '97'이기 때문에 내림차순 정렬만해주면 된다.

+ Recent posts