summaryrefslogtreecommitdiff
path: root/Year_1/Programming_2/exercises/carattere-maggiore.cc
blob: 2e89fcdfc5b5284d4d2473092403bd14861d84e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
#include<map>
#include<fstream>

using namespace std;



int main() {
    ifstream in("input.txt");
    ofstream out("output.txt");

    for(int ts = 0; ts < 100; ++ts) {
        string line;
        getline(in, line);
        map<char, int> chs;
        for(auto const& c : line) {
            if(c == ' ') continue;
            if(chs.find(c) != chs.end())
                chs[c]++;
            else
                chs[c] = 1;
        }
        int n = 0;
        char c = 'a';
        for(auto const& i : chs) {
            if(i.second >= n) {
                if(i.first >= c) {
                    n = i.second;
                    c = i.first;
                }
            }
        }
        out << c << ' ' << n << endl;
    }

    out.close();
    in.close();
    return 0;
}