文章
34
粉丝
0
获赞
6
访问
984
#include<bits/stdc++.h>
using namespace std;
int main(){
string line;
while(getline(cin, line)){
vector<char> letters;
// 提取并存储字母
for(char &c : line){
if(isalpha(c)) letters.push_back(c);
}
// 对字母序列进行稳定排序
stable_sort(letters.begin(), letters.end(), [](char a, char b){
return tolower(a) < tolower(b);
});
// 重构字符串,跳过原有的非字母进行字母插入
int idx = 0;
for(char &c : line){
if(isalpha(c)) c = letters[idx ++];
}
// 输出排序后的结果
cout << line << '\n';
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发