思路:
直接用sort()排序
解答:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
char str[200];
while(gets(str) != NULL) {
int str_len = strlen(str);
sort(str, str + str_len);
printf("%s\n", str);
}
return 0;
}
坑:
scanf(%s)遇到空格会结束输入。
本文介绍了一种利用C++标准库中的sort()函数对字符串进行排序的方法。通过实例演示了如何读取字符串,对其进行排序并输出,解决了scanf在遇到空格时停止输入的问题。
387

被折叠的 条评论
为什么被折叠?



