题解 | #字符串排序#

字符串排序

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;
    
}
#刷题#
全部评论

相关推荐

在改简历的大卫很认真:天天有面试 = 你已经在 offer 门口了。 海投能面成这样,说明你的简历、基础、学历都是过关的,缺的只是一次刚好匹配的缘分。 关于你说的 SQL 恐惧,我帮你捋一下: - 面试里考来考去,真就那几类: 分组、去重、关联、子查询、窗口函数(row_number、rank、sum 开窗) ​ - 面试官要的不是“写得花里胡哨”,而是思路稳、不出错。 你恐惧的本质不是不会, 是怕临场卡壳、怕写错、怕被追问。
点赞 评论 收藏
分享
01-30 09:45
燕山大学 Java
喵_coding:这种直接跑就完事了 哪有毕业了才签合同 任何offer和三方都没有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务