문자열 s에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 문자열을 리턴하는 함수, solution을 완성해주세요.
s는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 간주합니다.
str은 길이 1 이상인 문자열입니다.
s return
Zbcdefg gfedcbZ
#include <string>
#include <vector>
using namespace std;
string solution(string s) {
int temp;
for(int i = 0; i < s.size(); i++)
{
for(int j = 0; j < s.size()-1; j++)
{
if(s[j] < s[j+1])
{
temp = s[j];
s[j] = s[j+1];
s[j+1] = temp;
}
}
}
string answer = s;
return answer;
}
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string s) {
sort(s.begin(), s.end(), greater<char>());
return s;
}
sort함수의 greater() <-- 내림차순을 이용하면 쉽다...