forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecount.cpp
52 lines (42 loc) · 982 Bytes
/
recount.cpp
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
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
int main() {
string s;
vector<string> names;
unordered_map<string, int> votes;
while(getline(cin, s)) {
if(s == "***") {
break;
}
if(votes.count(s) > 0) {
votes.find(s)->second++;
}
else {
names.push_back(s);
votes.insert({s, 0});
}
}
int maxIndex = 0;
bool tie = false;
for(int i = 1; i < names.size(); i++) {
int currentVotes = votes.find(names[i])->second;
int maxVotes = votes.find(names[maxIndex])->second;
if(currentVotes == maxVotes) {
tie = true;
}
if(currentVotes > maxVotes) {
tie = false;
maxIndex = i;
}
}
if(tie) {
cout << "Runoff!" << endl;
}
else {
cout << names[maxIndex] << endl;
}
}