文章
52
粉丝
68
获赞
22
访问
11.6k
#include <bits/stdc++.h>
using namespace std;
bool compare(char c,char b){
if(c>='A'&&c<='Z')c=c-'A'+'a';
if(b>='A'&&b<='Z')b=b-'A'+'a';
return c<b;
}
int main(){
string s;
while(getline(cin,s)){
string c;
for(auto x:s){
if((x>='A'&&x<='Z')||(x>='a'&&x<='z'))c+=x;
}
stable_sort(c.begin(),c.end(),compare);
int j=0;
for(int i=0;i<s.size();i++){
char x=s[i];
if((x>='A'&&x<='Z')||(x>='a'&&x<='z'))cout<<c[j++];
else cout<<s[i];
}cout<<endl;
}
}
我们先把需要排序的提取出来,然后按照原来的s的位置模版进行输出即可
登录后发布评论
暂无评论,来抢沙发