文章

38

粉丝

11

获赞

2

访问

17.4k

头像
字母统计 题解:用的map
P1292 上海交通大学机试题
发布于2024年8月25日 18:05
阅读数 179

#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    while (getline(cin,s)){
        map<char,int> m;
        int len = s.size();
        char c = 0;
        for(int i = 0;i < 26;i++){
            c = 'A' + i;
            m[c] = 0;
        }
        for(int i = 0;i < len;i++){
            if(s[i] >= 'A' && s[i] <= 'Z')
                m[s[i]]++;
        }
        for(map<char,int> :: iterator t = m.begin();t != m.end();t++){
           cout << t->first << ":" << t->second <<endl;
        ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发