1042 字符统计(20 分)

#include
#include
#include
using namespace std;
string s;
int hashtable[256];
int main()
{
    getline(cin, s);
    int maxtime = 0;
    char ans;
    for (int i = 0; i < s.length(); i++)
    {
        if (isalpha(s[i]))
        {
            s[i] = tolower(s[i]);
            hashtable[s[i]]++;
            if (hashtable[s[i]] > maxtime)maxtime = hashtable[s[i]], ans = s[i];
            else if (hashtable[s[i]] == maxtime&&s[i] < ans)ans = s[i];
        }
    }
    printf("%c %d", ans, maxtime);
    return 0;
}

你可能感兴趣的:(1042 字符统计(20 分))