根据字典序进行排序,这里用到了sort是c++的用法,以前的代码,有大神指导下才用了sort,这里接触有点早。可以直接按数字把它当成asc码数字处理,所以排数字就行了。
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
using namespace std;
int main() {
char str[4];
while(scanf("%s",str)!=EOF) {
sort(str,str+3);
for(int i=0; i<3; i++) {
if(i==2)
printf("%c\n",str[i]);
if(i<2)
printf("%c ",str[i]);
}
}
return 0;
}
本文介绍了一个使用C++实现的字符串字典序排序算法。通过调用STL中的sort函数,对输入的字符串进行排序,并展示了如何输出排序后的结果。此方法适用于对字符或字符串按字典序进行排序的需求。
902

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



