U E D R , A S I H C RSS

Contest Score Board/차영권

소감

{{| 2005/06/18 Accepted 0:00.000 64 |}}

푼 문제수와 Time 패널티가 모두 같은 때에는 팀 번호가 작은 순으로 출력해야된다.

코드

~cpp 
#include <iostream>
using namespace std;

#define nTeam 101			// 팀 수
#define nProblem 9			// 문제 번호

// Team 구조체
struct Team
{
	int solvedProblem;		// 푼 문제의 수
	int timePenalty;		// 시간 패널티
	bool incorrectSubmit[nProblem];
	bool correctSubmit[nProblem];
};

void init(Team *team);
void InputInformation(Team *team, bool *joined);
void RankTeam(Team *team, bool *joined);

int main()
{
	Team team[nTeam] = {{0, }, {0, }, {false, }, {false, }};
	bool joined[nTeam] = {false, };
	int nCase;
	int count = 0;
	
	cin >> nCase;
	cin.get();
	cin.get();

	while (count < nCase)
	{	
		init(team);
		InputInformation(team, joined);
		RankTeam(team, joined);
		if (count < nCase-1)
			cout << endl;
		count++;
	}

	return 0;
}

void init(Team *team)
{
	int i, j;
	for (i=1 ; i<nTeam ; i++)
	{
		for (j=1 ; j<=nProblem ; j++)
		{
			team[i].correctSubmit[j] = false;
			team[i].incorrectSubmit[j] = false;
		}
		team[i].solvedProblem = 0;
		team[i].timePenalty = 0;
	}
}

void InputInformation(Team *team, bool *joined)
{
	int teamNumber, problemNumber, timePenalty;
	char state;

	while (cin.peek() != EOF) 
	{ 
		if (cin.peek() == '\n') 
		{ 
			cin.get(); 
			break; 
		}

		cin >> teamNumber >> problemNumber >> timePenalty >> state;
		cin.get();

		joined[teamNumber] = true;

		switch (state)
		{
		case 'I':
			team[teamNumber].incorrectSubmit[problemNumber] = true;
			break;
		case 'C':
			if (team[teamNumber].correctSubmit[problemNumber] == false)
			{
				team[teamNumber].solvedProblem++;
				team[teamNumber].timePenalty += timePenalty;
				if (team[teamNumber].incorrectSubmit[problemNumber] == true)
					team[teamNumber].timePenalty += 20;
				team[teamNumber].correctSubmit[problemNumber] = true;
			}		
			break;
		}
	}
}

void RankTeam(Team *team, bool *joined)
{
	int i;
	int bestTeam;
	int isBreak;

	while (1)
	{
		for (i=1 ; i<nTeam ; i++)
		{
			if (joined[i])
			{
				bestTeam = i;
				isBreak = 0;
				break;
			}
		}

		if (isBreak != 0)
			break;

		for (i=1 ; i<nTeam ; i++)
		{
			if (joined[i])
			{
				if (team[i].solvedProblem > team[bestTeam].solvedProblem)
					bestTeam = i;			// 푼 문제수가 가장 많은 팀을 뽑는다
				else if (team[i].solvedProblem == team[bestTeam].solvedProblem
					&& team[i].timePenalty < team[bestTeam].timePenalty)
						bestTeam = i;
				else
					continue;
			}
		}	
		cout << bestTeam << " " << team[bestTeam].solvedProblem << " "
		     << team[bestTeam].timePenalty << endl;
		joined[bestTeam] = false;
		isBreak = 1;
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0914 sec