题解 | #字符串排序#

字符串排序

https://www.nowcoder.com/practice/5190a1db6f4f4ddb92fd9c365c944584

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
using namespace std;

int main(){
    
    string str;
    getline(cin, str);
    map<char, queue<char>> map;
    for(int i = 0; i < str.size(); i++) {
        if(isupper(str[i])) { //大写字母
            map[str[i]].push(str[i]);
        }
        else if(islower(str[i])) {//小写字母
            map[toupper(str[i])].push(str[i]);
        }
        else{
            
        }
    }
    auto it = map.begin();
     for(int i = 0; i < str.size(); i++) {
         if(isupper(str[i]) || islower(str[i])) {
             str[i] = it ->second.front();
             it ->second.pop();
             if(it -> second.empty()) {
                 it++;
             }
         }
     }
    cout << str;
    
}
#刷题#
全部评论

相关推荐

ldf李鑫:不说公司名祝你以后天天遇到这样的公司
点赞 评论 收藏
分享
04-10 11:56
如皋中学 Java
高斯林的信徒:双c9能简历挂的?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务