字符串内排序

问题 D: 字符串内排序
时间限制: 1 Sec 内存限制: 32 MB
提交: 550 解决: 237
[提交][状态][讨论版][命题人:外部导入]
题目描述
输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。

输入
测试数据有多组,输入字符串。

输出
对于每组输入,输出处理后的结果。

样例输入
tianqin
样例输出
aiinnqt
提示
注意输入的字符串中可能有空格。
自己代码:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() {
	char str[200],str2[200],j=0;
	while (gets(str)!=NULL) {
		j = 0;
		sort(str, str + strlen(str));
		printf("%s\n", str);
	}
	system("pause");
	return 0;
}
注意:
当用scanf("%s",str)时是以换行或空格为分割的。我用gets(str)就可以`,gets以回车为分割


猜你喜欢

转载自blog.csdn.net/qq_35966478/article/details/86628425
今日推荐