九度OJ 1054 字符串内排序
题目分析:
简单的排序。设置字符串保存输入数据,然后排序。
源代码:
[cpp]
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
while (cin>>s)
{
if (s.length() > 200)
{
break;
}
char a;
for (int i = 0; i < s.length(); i++)
{
for (int j = i + 1; j < s.length(); j++)
{
if (s[i] > s[j])
{
a = s[i];
s[i] = s[j];
s[j] = a;
}
}
}
cout<<s<<endl;
}
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
while (cin>>s)
{
if (s.length() > 200)
{
break;
}
char a;
for (int i = 0; i < s.length(); i++)
{
for (int j = i + 1; j < s.length(); j++)
{
if (s[i] > s[j])
{
a = s[i];
s[i] = s[j];
s[j] = a;
}
}
}
cout<<s<<endl;
}
}
补充:软件开发 , C++ ,