The 11th Blue Bridge Cup-Word Analysis

Title description
Xiaolan is learning a magical language. The words in this language are made up of lowercase English letters. Some words are very long, far exceeding the length of normal English words.

Xiaolan had been learning for a long time and couldn't remember some words. He planned not to remember these words completely, but to distinguish words based on which letter appeared the most.

Now, please help Xiaolan. After giving a word, help him find the most frequent letter and the number of times this letter appears.

Input format The
input line contains one word, and the word only consists of lowercase English letters.

Output format The
first line contains an English letter, which indicates which letter appears the most in the word; the
second line contains an integer, which indicates the number of times the letter that appears the most appears in the word.

If there are multiple letters appearing the same number of times, the one with the smallest lexicographic order is output

Input example 1
lanqiao

Sample output 1
a
2

Input sample 2
longlonglongistoolong

Sample output 2
o
6

Data range
For all evaluation use cases, the length of the input word does not exceed 1000.


Problem solution
simulation:

#include <iostream>
using namespace std;

int cnt[27];

int main()
{
    
    
    string s;
    cin >> s;
    
    for (int i = 0; i < s.size(); i ++) cnt[s[i] - 'a'] ++;
    
    char alpha;
    int maxv = 0;
    for (int i = 0; i < 26; i ++)
        if(cnt[i] > maxv)
        {
    
    
            maxv = cnt[i];
            alpha = i + 'a';
        }
        
    cout << alpha << endl;
    cout << maxv << endl;
    return 0;
}

Lanqiao Cup C/C++ Group Provincial Competition Past Years Questions

Guess you like

Origin blog.csdn.net/weixin_46239370/article/details/115293359