c++输入一个字符串要求所有字符按ASCII码降序排序

c++输入一个字符串要求所有字符按ASCII码降序排序

给你一个用string的例子:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(const char& c1, const char& c2)
{
return c1>c2;
}
int main()
{
string s;
cin>>s;
sort(s.begin(),s.end(),cmp);
cout<<s<<endl;
return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答