Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

"Any names not in the list of candidates should be ignored"无视这句话就过了- -!!!

Posted by shezepo at 2013-05-15 22:47:56 on Problem 2643
如下就过了:
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator