题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <algorithm> #include <iostream> #include <bits/stdc++.h> #include <vector> using namespace std; int main() { string str; string zimu_str; vector<string> reg(26); getline(cin,str); for(int i = 0; i < str.size(); i++){ if(str[i] - 'a' < 26){ reg[str[i] - 'a'] += str[i]; } if(str[i] - 'A' < 26){ reg[str[i] - 'A'] += str[i]; } } for(auto i = 0; i < 26; i++){ for(auto j = 0; j < reg[i].size();j++){ zimu_str += reg[i][j]; } } int n = 0; for(int i = 0; i < str.size(); i++){ if((str[i] >= 'a' && str[i] <='z')||(str[i] >= 'A' && str[i] <='Z')) cout << zimu_str[n++]; else cout << str[i]; } cout << endl; } // 64 位输出请用 printf("%lld")