hiho week 165 register

Ended

Participants:334

Verdict:Accepted
Score:100 / 100
Submitted:2017-08-28 16:25:04

Lang:G++

Edit
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
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    
    string input = "", output = "";
    vector<int> letters(26);
    while(cin >> input){
        output = "";
        for(vector<int>::size_type ind = 0; ind < letters.size(); ++ind){
            letters[ind] = 0;
        }
        for(string::size_type ind = 0; ind < input.size(); ++ind){
            ++letters[input[ind] - 'a'];
        }
        
        int lastInd = -1;
        bool found = false;
        int len = input.size();
        while(len--){ 
            found = false; // Remember to reset
            // Find the letters with max number to see if it exceeds ceil(len/2)
            int max = letters[0], selected = 0;
            for(string::size_type ind = 1; ind < letters.size(); ++ind){
                if(letters[ind] > max){
                    max = letters[ind];
                    selected = ind;
                }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX