题解 | #字符串排序#
字符串排序
https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(int argc, char* argv[]){
string str;
getline(cin, str);
multimap<char, int> dic;
for(int i = 0; i < str.size(); ++i){
if(str[i] >= 'a' && str[i] <= 'z'){
dic.insert(make_pair(str[i], 1));
}
if(str[i] >= 'A' && str[i] <= 'Z'){
dic.insert(make_pair(tolower(str[i]), 2));
}
}
auto iter = dic.begin();
for(int i = 0; i < str.size(); ++i){
if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'){
if(iter->second == 1){
cout << iter->first;
}
if(iter->second == 2){
cout << (char)toupper(iter->first);
}
++iter;
}
else{
cout << str[i];
}
}
cout << endl;
return 0;
}