题解 | #字符串排序#

字符串排序

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

#include <iostream>
#include <string>
#include <deque>
using namespace std;

int main(){
    string str;
    deque<char> m1help;
    getline(cin, str);
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < str.length(); j++){
            if(str[j] == 'a' + i || str[j] == 'A' + i)
                m1help.push_back(str[j]);
        }
    }
    for(int i = 0; i < str.length(); i++){
        if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'){
            str[i] = m1help.front();
            m1help.pop_front();
        }
    }
    cout << str;
    return 0;
}

提取出字母,一轮堆排序,放回字母,结束

全部评论

相关推荐

11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 11:29
已编辑
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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