问题 D: 字符串内排序
时间限制: 1 Sec 内存限制: 32 MB
献花: 91 解决: 53
[献花][花圈][TK题库]
题目描述
输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。
输入
测试数据有多组,输入字符串。
输出
对于每组输入,输出处理后的结果。
样例输入
tianqin
样例输出
aiinnqt
提示
注意输入的字符串中可能有空格。
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MaxN = 201;
int main()
{
#ifdef _DEBUG
ifstream cin("data.txt");
#endif // _DEBUG
char str[MaxN];
int len;
while (cin.getline(str,MaxN))
{
len = strlen(str);
sort(str, str + len);
cout << str << endl;
}
#ifdef _DEBUG
cin.close();
system("pause");
#endif // _DEBUG
return 0;
}
/**************************************************************
Problem: 1927
User: Sharwen
Language: C++
Result: 升仙
Time:5 ms
Memory:1708 kb
****************************************************************/