题解 | #字母统计#

字母统计

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

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

int main() {
    string str;
    map<char, int> tempMap = {{'A',0},{'B',0},{'C',0},{'D',0},
    {'E',0},{'F',0},{'G',0},{'H',0},
    {'I',0},{'J',0},{'K',0},{'L',0},
    {'M',0},{'N',0},{'O',0},{'P',0},
    {'Q',0},{'R',0},{'S',0},{'T',0},
    {'U',0},{'V',0},{'W',0},{'X',0},{'Y',0},{'Z',0}};
    while (getline(cin, str)) {
        for (char & i : str) {
            if ('A' <= i && i <= 'Z') {
                tempMap[i]++;
            }
        }
        for (auto & iter : tempMap) {
            printf("%c:%d\n",iter.first,iter.second);
            iter.second = 0;
        }
    }
    return 0;
}

全部评论

相关推荐

04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
04-18 15:58
已编辑
门头沟学院 设计
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务