题解 | #字符串排序#哈希表 简洁易懂代码

字符串排序

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

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

int main()
{
    map<char, string> hash;
    string str;
    getline(cin, str);
    for(int i = 0; i < str.size(); i++)
        if(isalpha(str[i]))
            hash[tolower(str[i])].push_back(str[i]);
    string sortStr;
    for(auto it : hash)
        sortStr += it.second;
    int j = 0;
    for(int i = 0; i < str.size(); i++)
        if(isalpha(str[i]))
            str[i] = sortStr[j++];
    cout << str << endl;    
    return 0;
}
全部评论

相关推荐

08-12 09:16
Java
牛客38753147...:后端的竞争者一届比一届卷,前两年非985还很多,一段大厂实习就已经非常优秀了。 现在985硕多如狗,人手一段大厂实习,而且腾讯和百度今年都宣布实习扩招了一倍不止,越来越多的人从本一研一就开始刷实习,信息差也基本没有了。可以预见的,以后只会越来越卷。
投递快手等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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