~cpp
// no10258 - Contest Score Board
#include <iostream>
using namespace std;
#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))
const int NUMBER_TEAM = 101;
const int NUMBER_PROBLEM = 10;
const int TIME_PENALTY = 20;
typedef struct{
int timeProblem[NUMBER_PROBLEM];
int penalty;
int numberSuccessProblem;
}ContestTeam;
void inputInfoContest(ContestTeam * team, bool * isSumit);
void initialize(ContestTeam * team, bool * isSumit);
void initializeTeam(ContestTeam * team);
void initializeIsSumit(bool * isSumit);
int settingRank(bool * isSumit, int * rankTeam);
void concludeRank(ContestTeam * team, int * rankTeam, int numberSumitTeam);
void printRank(ContestTeam * team, int * rankTeam, int numberSumitTeam);
int main()
{
int numberCase;
cin >> numberCase;
cin.get();
cin.get();
ContestTeam team[NUMBER_TEAM];
bool isSumit[NUMBER_TEAM];
int rankTeam[NUMBER_TEAM];
int numberSumitTeam;
int i;
for (i = 0; i < numberCase; i++)
{
initialize(team, isSumit);
inputInfoContest(team, isSumit);
numberSumitTeam = settingRank(isSumit, rankTeam);
concludeRank(team, rankTeam, numberSumitTeam);
printRank(team, rankTeam, numberSumitTeam);
if (i != numberCase - 1)
cout << endl;
}
return 0;
}
void initialize(ContestTeam * team, bool * isSumit)
{
initializeTeam(team);
initializeIsSumit(isSumit);
}
void initializeTeam(ContestTeam * team)
{
for (int i = 1; i < NUMBER_TEAM; i++)
{
for (int j = 1; j < NUMBER_PROBLEM; j++)
team[i].timeProblem[j] = 0;
team[i].penalty = 0;
team[i].numberSuccessProblem = 0;
}
}
void initializeIsSumit(bool * isSumit)
{
for (int i = 1; i < NUMBER_TEAM; i++)
isSumit[i] = 0;
}
int settingRank(bool * isSumit, int * rankTeam)
{
int count = 1;
for (int i = 1; i < NUMBER_TEAM; i++)
{
if (isSumit[i] == true)
rankTeam[count++] = i;
}
return count;
}
void inputInfoContest(ContestTeam * team, bool * isSumit)
{
int numTeam, numProblem, time;
char L;
while (cin.peek() != EOF)
{
if (cin.peek() == '\n')
{
cin.get();
break;
}
cin >> numTeam >> numProblem >> time >> L;
isSumit[numTeam] = true;
switch (L)
{
case 'C':
if (team[numTeam].timeProblem[numProblem] == -1)
break;
team[numTeam].penalty += team[numTeam].timeProblem[numProblem] + time;
team[numTeam].numberSuccessProblem++;
team[numTeam].timeProblem[numProblem] = -1;
break;
case 'I':
if (team[numTeam].timeProblem[numProblem] == -1)
break;
team[numTeam].timeProblem[numProblem] += TIME_PENALTY;
break;
}
cin.get();
}
}
void concludeRank(ContestTeam * team, int * rankTeam, int numberSumitTeam)
{
int top;
int temp;
for (int i = 1; i < numberSumitTeam; i++)
{
top = i;
for (int j = i + 1; j < numberSumitTeam; j++)
{
if (team[rankTeam[top]].numberSuccessProblem < team[rankTeam[j]].numberSuccessProblem)
SWAP(rankTeam[top], rankTeam[j], temp);
else if (team[rankTeam[top]].numberSuccessProblem == team[rankTeam[j]].numberSuccessProblem)
{
if (team[rankTeam[top]].penalty > team[rankTeam[j]].penalty)
SWAP(rankTeam[top], rankTeam[j], temp);
}
}
}
}
void printRank(ContestTeam * team, int * rankTeam, int numberSumitTeam)
{
for (int i = 1; i < numberSumitTeam; i++)
cout << rankTeam[i] << " " << team[rankTeam[i]].numberSuccessProblem << " " << team[rankTeam[i]].penalty << endl;
}