第1个回答 2013-05-17
#include<iostream>
using namespace std;
int main()
{
char string[50];
for(int i=0;i<50;i++)
{
cin>>string[i];
if(string[i]=='0')
break;
}
if(i==50)
{
cout<<"输入字符过多。"<<endl;
}
else
{
char temp;
for(int m=0;m<i-1;m++)
{
for(int n=m+1;n<i;n++)
{
if(string[m]>string[n])
{
temp=string[m];
string[m]=string[n];
string[n]=temp;
}
}
}
for(int j=0;j<i;j++)
cout<<string[j];
cout<<endl;
}
return 0;
}
第2个回答 2013-05-17
#include <iostream>
#include <cctype>
#include <algorithm>
using namespace std;
// 字母分大小写
bool op(char a, char b)
{
return tolower(a) < tolower(b);
}
int main()
{
char s[256];
cin >> s;
sort(s, s+strlen(s), op);
cout << s;
}