每个小组中四支球队。每个小组中的球队按照如下规则排序:
球队会根据比赛结果获得积分。一场比赛的双方被称为主队和客队。如果其中一方进球数多于另一方,那么进球较多的一方获得3 分,另一方获得0 分。如果双方打成平手,则各得1分。
球队的净胜球数是其进球数减去失球数(不考虑该球队在比赛中作为主队还是客队)。
积分较高的球队排名更加靠前。
如果两支球队积分相同,那么净胜球数较多的球队排名靠前。
小组的各队伍进行循环赛
给定一个小组内12 场比赛的结果
请求出小组的排名第一和第二的两支球队。
#include<iostream>
#include<algorithm>
using namespace std;
struct team
{
string name;
int score=0;
int ball=0;
};
int findS(string s,team* t)
{
for(int i=0;i<4;i++)
if(s==t[i].name) return i;
return 5;
}
bool cmp(team x,team y)
{
if(x.score!=y.score) return x.score>y.score;
else return x.ball>y.ball;
}
int main()
{
int T;cin>>T;
for(int time=0;time<T;time++)
{
team t[4];
string s1,s,s2;
int a,b,i,x,y,c=0;
for(int k=0;k<12;k++)
{
cin>>s1>>a>>s>>b>>s2;
if(a==b) x=y=1;
else if(a>b) {x=3; y=0;}
else {x=0; y=3;}
i=findS(s1,t);
if(i!=5)
{
t[i].score+=x;
t[i].ball+=a-b;
}
else
{
t[c].name=s1;
t[c].score=x;
t[c].ball=a-b;
c++;
}
i=findS(s2,t);
if(i!=5)
{
t[i].score+=y;
t[i].ball+=b-a;
}
else
{
t[c].name=s2;
t[c].score=y;
t[c].ball=b-a;
c++;
}
}
sort(t,t+4,cmp);
cout<<t[0].name<<" "<<t[1].name<<endl;
}
}