string排序的奇技淫巧

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

以上为

用sort对string类型进行排序

如果要降序排列,则用std::reverse(s.begin(),s.end());进行string反串!

谨记头文件#include <algorithm>!!

猜你喜欢

转载自www.cnblogs.com/df11gcode/p/9173212.html