计算某字母出现次数

简介

简单

code

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

int main() {
    string s;
    getline(cin, s);
    string t;
    cin >> t;
    map<char, int> cc;
    for(auto it : s){
        if(it >='a' && it <= 'z') cc[it-'a' + 'A']++;
        else cc[it]++;
    }
    if(t[0] >='a' && t[0] <='z') cout << cc[t[0] - 'a' + 'A'] << endl;
    else cout << cc[t[0]] <<endl;
    return 0;
}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/14918974.html