algorithm算法库里的sort函数超级好用,sort()真真的是一个宝藏函数!!!
只要将需要排序的string的首尾地址放入
也可以用自己定义cmp函数当成排序规则 传参
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
sort(s.begin(), s.end());
cout << s << endl;
return 0;
}
对string类型的数组也可以进行排序
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string ss[5];
int i = 0;
while(cin >> ss[i++]){
if(i == 5) break;
}
sort(ss, ss+5);
for(int j = 0; j < 5; j++){
cout << ss[j] << endl;
}
}
sort谁用谁知道,舒服的不谈