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

是不是因为getline()用的不对才WA的呢?

Posted by BlueBlood at 2005-12-06 13:01:44 on Problem 2643
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
	int n,m;
	int i,j;
	string candidate[21];
	string party[21];
	int votes[21];
	string ballot;

	cin >> n;
	cin.ignore();
	
	for (i = 0; i < n; i++)
	{
		
		getline(cin,candidate[i]);
		getline(cin,party[i]);

		votes[i] = 0;
	}

	cin >> m; 
	cin.ignore();

	for ( i = 0; i < m; i++)
	{
		getline(cin,ballot);

		for (j = 0; j < n; j++)
		{
			if (ballot == candidate[j])
			{
				votes[j]++;
				break;
			}
		}
	}

	bool flag = true;
	int nmax = 0;
	int index;

	for( i = 0; i < n ;i++)
	{
		if (votes[i] != votes[0])
			flag = false;
		if ( votes[i] > nmax)
		{
			nmax = votes[i];
			index = i;
		}
	}

	if (flag)
	{
		cout << "tie" << endl;
	}
	else
	{
		cout << party[index] << endl;
	}


	system("pause");
	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