#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<string>
#include<map>
#include<vector>
typedef long long ll;
using namespace std;
struct node
{
string name;
string name2;
int pts; //积分
int gms; //参赛场次
int goal;//进球数
int suffer;//失球数
int gs; //净进球数
double p; //百分比
int index; //第二次排序需要,为了使第一次按照字母所排的序列顺序不变。
}team[30];
bool cmp1(const node&a,const node&b )
{
return a.name2<b.name2;
}
bool cmp2(const node&a,const node&b)
{
if(a.pts!=b.pts)
return a.pts>b.pts;
else if(a.gs!=b.gs)
return a.gs>b.gs;
else if(a.goal!=b.goal)
return a.goal>b.goal;
else
return a.index<b.index;
}
void print(bool f,int cnt,node a)
{
if(!f)
printf("%2d.",cnt);
else
printf(" ");
printf("%16s%4d%4d%4d%4d%4d",a.name.c_str(),a.pts,a.gms,a.goal,a.suffer,a.gs);
if(a.gms==0)
printf(" N/A\n");
else printf("%7.2f\n",a.p);
}
bool eq(const node&a ,const node&b)
{
if(a.pts==b.pts&&a.gs==b.gs&&a.goal==b.goal)
return true;
else
return false;
}
int main()
{
int n,m;
char c[20];
int flag=0;
int z=1;
while(~scanf("%d%d",&n,&m)&&(n||m))
{
if(flag)
printf("\n");
for(int i=0;i<n;i++)
{
scanf(" %s",c);
team[i].name=c;
team[i].name2.clear();
int len=strlen(c);
for(int j=0;j<len;j++)
team[i].name2+=tolower(c[j]);
team[i].pts=team[i].gms=team[i].goal=team[i].suffer=0;
}
sort(team,team+n,cmp1);
map<string,int> mmap;
for(int i=0;i<n;i++)
{
team[i].index=i;
mmap[team[i].name]=i;
}
char c1[20],c2[20];
int n1,n2;
int goal1,goal2;
for(int i=0;i<m;i++)
{
scanf("%s %d - %d %s",c1,&goal1,&goal2,c2);
n1=mmap[c1];
n2=mmap[c2];
team[n1].goal+=goal1;
team[n2].goal+=goal2;
team[n1].gms++;
team[n2].gms++;
team[n1].suffer+=goal2;
team[n2].suffer+=goal1;
if(goal1>goal2)
team[n1].pts+=3;
else if(goal1<goal2)
team[n2].pts+=3;
else
{
team[n1].pts++;
team[n2].pts++;
}
}
for(int i=0;i<n;i++)
{
team[i].gs=team[i].goal-team[i].suffer;
if(!team[i].gms)
continue;
team[i].p=(team[i].pts*100.0)/(team[i].gms*3.0);
}
sort(team,team+n,cmp2);
print(false,1,team[0]);
for(int i=1;i<n;i++)
print(eq(team[i],team[i-1]),i+1,team[i]);
flag=1;
}
return 0;
}
UVA 10698 (Football Sort) (排序模拟)
最新推荐文章于 2018-09-10 17:54:56 发布