题解 | #字符串排序#

字符串排序

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

参考评论区题解

#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void sort_str(string& str) {
    vector<vector<char>> v(26);
    for (char c: str) {
        if (!isalpha(c)) continue;
        if (c >= 'a') v[c-'a'].push_back(c);
        else v[c-'A'].push_back(c);
    }
    int k = 0;
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < v[i].size(); j++) {
            while (!isalpha(str[k])) k++;
            str[k++] = v[i][j];
        }
    }
}

int main() {
    string str;
    getline(cin, str);
    sort_str(str);
    cout << str;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-19 20:55
因为业务不是喜欢的,所以就没去,现在实习工作也有很多dirtywork,很后悔,怎么能舔回这个offer啊
flmz_Kk:试一试跟hr舔回来,不过保不齐米的活也有很多dirtywork,只能说不要美化自己没走过的路
点赞 评论 收藏
分享
代码飞升:别用口语,后端就写后端,前端就写前端,最后别光后悔
点赞 评论 收藏
分享
我面试,她问我有女朋友没
不太迷人的反派_:不过对象,还会结合你老家,意向城市等等,看你是否稳定。哥们,别多想
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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