题解 | #字符串排序#用26个队列保存所有字母
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <iostream> #include <string> #include <vector> #include <bits/stdc++.h> using namespace std; int main(){ string str, line; getline(cin, line); int len = line.size(); vector<queue<char>> f(26); for(int i=0; i<len; ++i) { char a = line[i]; if(isalpha(a)) { f[tolower(a) - 'a'].push(a); } } int i=0; for(int j=0; j<26; ++j) { while(!f[j].empty()) { if(isalpha(line[i])) { line[i] = f[j].front(); f[j].pop(); } ++ i; if(i == len) break; } if(i == len) break; } cout << line << endl; return 0; }