Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
"Any names not in the list of candidates should be ignored"无视这句话就过了- -!!!如下就过了: #include <iostream> #include <string> #include <map> using namespace std; int main() { int n; cin >> n; getchar(); string candidate, party; map<string, string> association; for (int i = 0; i < n; ++i) { getline(cin, candidate); getline(cin, party); association[candidate] = party; } int m; cin >> m; getchar(); map<string, int> votes; for (int i = 0; i < m; ++i) { getline(cin, candidate); //if (association.find(candidate) != association.end()) { ++votes[candidate]; //} } bool tie = false; int maxVote = 0; for (map<string, int>::iterator iter = votes.begin(); iter != votes.end(); ++iter) { if (iter->second > maxVote) { candidate = iter->first; maxVote = iter->second; tie = false; } else if (iter->second == maxVote) { tie = true; } } if (tie) { cout << "tie" << endl; } else { cout << association[candidate] << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator