cin 不能直接读入空格,可以用getline(PAT统计字符数)

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

int main(){
    string str;
    int a[200] = {0};
    
//    cin >> str;
    getline(cin, str);
    for(int i = 0; i < str.length(); i++){
        if(str[i] >= 'a' && str[i] <= 'z')
            a[str[i]]++;
        if(str[i] >= 'A' && str[i] <= 'Z')
            a[str[i] + 32]++;            
    }
    int max = 90;
    for(int i = 'a'; i <= 'z'; i++)
        if(a[max] < a[i])
            max = i;
    cout << (char)max << " " << a[max];
    return 0;
}

原文地址:https://www.cnblogs.com/zhumengdexiaobai/p/7224977.html