文章

11

粉丝

34

获赞

0

访问

2.6k

头像
字母统计 题解:
P1292 上海交通大学机试题
发布于2024年3月21日 16:17
阅读数 273

#include <cstdio>
using namespace std;
#include <string.h>
#include <iostream>
#include <map>
#include <stdlib.h>
int main() {
    map<char, int>M;
    for (int i = 0; i < 26; i++) {
        M['A' + i] = 0;
    }
    char s[1000];
    gets(s);
    int sl = strlen(s);
    for (int i = 0; i < sl; i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') {
            M[s[i]]++;
        }
    }
    //遍历map
    for (auto i : M) {
        cout << i.first << ":" << i.second << endl;
    }
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发