题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <cctype>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
bool compareFunc(char a, char b){
return tolower(a) < tolower(b);
}
int main() {
string input;
getline(cin,input);
vector<char> s;
for (auto& c:input) {
if(isalpha(c))
s.push_back(c);
}
stable_sort(s.begin(), s.end(),compareFunc);
string res = input;
int letter = 0;
for (int i=0; i<input.size();i++) {
if (isalpha(input[i])) {
res[i] = s[letter];
letter ++;
}
}
cout << res << endl;
}
// 64 位输出请用 printf("%lld")
凡岛公司福利 294人发布