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
| #include <algorithm> #include <vector> #include <iostream> #include <unordered_map> using namespace std;
int main(){ unordered_map<string,int> hash = { {"Bessie",0}, {"Elsie",0}, {"Daisy",0}, {"Gertie",0}, {"Annabelle",0}, {"Maggie",0}, {"Henrietta",0} }; int n; cin >> n; string str;int x; while (n--){ cin >> str >> x; hash[str] += x; } vector<int> q; for (auto &[k , v] : hash) q.push_back(v); sort(q.begin(),q.end()); q.erase(unique(q.begin(),q.end()),q.end()); if (q.size() == 1) cout << "Tie\n"; else{ int cnt = 0;string name; for (auto &[k , v] : hash){ if (v == q[1]){ name = k; cnt ++; } if (cnt > 1){ cout << "Tie\n"; break; } } if (cnt == 1) cout << name << '\n'; } return 0; }
|