题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/d2f088e655d44e4a85c16f7b99126211
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
bool comp(char lhs, char rhs) {
if (lhs < rhs) {
return true;
} else {
return false;
}
}
int main() {
char arr[21] ;
while (scanf("%s", arr) != EOF) {
string s = arr;
sort(arr, arr + s.size(), comp);
for (int i = 0 ; i < s.size(); ++i) {
printf("%c", arr[i]);
}
}
}
滴滴公司福利 1815人发布
查看5道真题和解析