题解 | #字母统计#(map解法)

字母统计

https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c

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

int main() {
    string str;
    while(cin >> str) {
        map<char, int> cnt;
        for(int i = 0;i < 26; i++) {
            cnt[char(int('A' + i))] = 0;
        }
        for(int i = 0;i < str.length(); i++) {
            if(str[i] >= 'A' && str[i] <= 'Z'){
                cnt[str[i]]++;
            }
        }
        for(auto iter = cnt.begin(); iter != cnt.end(); iter++){
            cout << iter->first << ':' << iter->second << endl;
        }
        

    }
    return 0;
}

全部评论

相关推荐

刷牛客的我很豁达:你是不是对算法有什么误解,你没手握两篇顶刊顶会,还想搞算法岗,有顶刊顶会在算法岗算才入门
点赞 评论 收藏
分享
08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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