10258 – Contest Scoreboard 알고리즘

#include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

typedef struct Problem
{
bool isAccept;
int nPanelty;
Problem()
{
nPanelty=0;
isAccept=false;
}
};
typedef struct Team
{
int n;
int solved;
int time;
Problem p[100];
Team()
{
n=0; solved=0; time=0;
}
};

bool cmp(const Team& t1, const Team& t2)
{
if(t1.solved > t2.solved)
return true;
else if(t1.solved==t2.solved)
{
if(t1.time < t2.time)
return true;
else if(t1.time==t2.time)
if(t1.n < t2.n)
return true;
}
return false;
}

int main()
{
int n,team,prob,time;
char c;

scanf("%d",&n);
getchar();
getchar();
for(int i=0; i < n; i++)
{
//char ch = getchar();
map<int, int>m;
vector<Team> t;
int cnt=0; 
char line[255];
while(gets(line)&&line[0])
{
sscanf(line,"%d %d %d %c",&team,&prob,&time,&c);
if(m.find(team) == m.end())
{
m.insert(pair<int,int>(team,cnt++));
Team s;
s.n = team;
t.push_back(s);
}
switch(c)
{
case 'I': 
if(!t[m[team]].p[prob].isAccept)
t[m[team]].p[prob].nPanelty++;
break;
case 'C': 
if(!t[m[team]].p[prob].isAccept)
{
t[m[team]].p[prob].isAccept = true;
t[m[team]].solved++;
t[m[team]].time += t[m[team]].p[prob].nPanelty*20+time;
}
}
}
sort(t.begin(),t.end(),cmp);
if(i)
putchar('\n');
for(vector<Team>::iterator it = t.begin(); it != t.end(); it++)
{
printf("%d %d %d\n",it->n,it->solved,it->time);
}
}
return 0;
}

덧글

댓글 입력 영역