题解 | #字符串排序#

字符串排序

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

#include <algorithm>
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
    string str;
    string zimu_str;
    vector<string> reg(26);
    getline(cin,str);
    for(int i = 0; i < str.size(); i++){
        if(str[i] - 'a' < 26){
            reg[str[i] - 'a'] += str[i];
        }
        if(str[i] - 'A' < 26){
            reg[str[i] - 'A'] += str[i];
        }
    }

    for(auto i = 0; i < 26; i++){
        for(auto j = 0; j < reg[i].size();j++){
            zimu_str += reg[i][j];
        }
    }

    int n = 0;
    for(int i = 0; i < str.size(); i++){
        if((str[i] >= 'a' && str[i] <='z')||(str[i] >= 'A' && str[i] <='Z'))
            cout << zimu_str[n++];
        else
            cout << str[i];
    }
    cout << endl;
    
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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