题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); vector<pair<char,int>> sto; for (int i = 0; i < s.size(); ++i) if (isalpha(s[i])) sto.push_back({tolower(s[i]), i}); sort(sto.begin(), sto.end()); string ans = s; int p = 0; for (int i = 0; i < s.size(); ++i) if (isalpha(s[i])) ans[i] = s[sto[p++].second]; cout << ans; return 0; }