描述 | |
---|---|
知识点 | 字符串,排序 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | |
输出 | |
样例输入 | A Famous Saying: Much Ado About Nothing (2012/8). |
样例输出 | A aaAAbc dFgghh: iimM nNn oooos Sttuuuy (2012/8). |
将大小写字母都提出来,然后用稳定的冒泡排序对字母进行排序,排完之后再插入到原有的序列中即可。
#include <iostream>
#include <string>
using namespace std;
int main(){
string input;
getline(cin,input);
string temp;
for(int i=0;i<input.length();i++){
if(isalpha(input[i]))
temp += input[i];
}
for(int i=0;i<temp.length();i++){
for(int j=0;j<temp.length()-1-i;j++){
if(toupper(temp[j]) > toupper(temp[j+1])){
char c = temp[j];
temp[j] = temp[j+1];
temp[j+1] = c;
}
}
}
int k = 0;
for(int i=0;i<input.length();i++){
if(isalpha(input[i]))
input[i] = temp[k++];
}
cout<<input<<endl;
return 0;
}