题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include<iostream> #include<vector> using namespace std; int main() { vector<vector<char>> store(26); string s; string tem; int count = 0; int k = 0; while (getline(cin, s)) { for(int i = 0;i<s.size();i++){ if(s[i]>='a'&&s[i]<='z'){ store[s[i]-'a'].push_back(s[i]); continue; } if(s[i]>='A'&&s[i]<='Z'){ store[s[i]-'A'].push_back(s[i]); continue; } } for(int i = 0;i<store.size();i++){ if(!store[i].empty()){ for(int j = 0;j<store[i].size();j++){ tem += store[i][j]; } } } for(int k = 0;k<s.size();k++){ if((s[k]>='a'&&s[k]<='z')||s[k]>='A'&&s[k]<='Z'){ cout<<tem[count]; count++; }else{ cout<<s[k]; } } } return 0; }