牛客 2021年度训练联盟热身训练赛第二场 D题Soccer Standings

在这里插入图片描述

题目描述

Soccer fever has gripped the world once again, and millions of people from dozens of countries
will be glued to their TV sets for the World Cup. Being an enterprising sort, you’ve started up your own internet World Cup Soccer Channel for streaming matches online. Recently you came up with the idea of filling up the time between matches by having a couple of ‘experts’ offer critical analysis of games. For this purpose, you have devised a unique ranking system for soccer teams, which you must now implement.
The Problem:
Given a list of teams and a list of match scores, you must compute several quantities for each team. These are: the total number of goals scored over all their games, the total number of goals scored against them (goals allowed, for short), the number of wins, draws and losses, and the number of points scored so far. Points are to be computed as follows: winning a match nets a team 3 points, losing gets them nothing. In the event of a tie, both teams get 1 point.
In addition to this, you must order the teams correctly according to your new system. Teams are ordered according to points, from highest to lowest. In the event of a tie in points, the team that has a higher goal difference comes first. The goal difference is defined as the total number of goals scored by the team minus the total number of goals scored against them.
If there is still a tie (i.e., two or more teams have the same points and the same goal differences), the team with higher total goals scored comes first. If even this is tied, the team whose name comes first in alphabetical order goes first.

输入描述:

The first input line contains a positive integer, n, indicating the number of data sets to be processed. The first line of each data set consists of two positive integers T (T ≤ 30) and G (G ≤
400) – the number of teams in this group and the total number of games played by them. The next line contains T unique names separated by single spaces. Each name is a single uppercase word with no more than 15 characters.
Each of the next G input lines will contain the results of a match. Each line is of the form
<country_1> <score_1> <country_2> <score_2>. For example, “Greece 2 Nigeria 1” indicates that Greece and Nigeria played a game with score 2-1. All four terms will be separated by single spaces.

输出描述:

At the beginning of output for each data set, output “Group g:” where g is the data set number, starting from 1. Next you should print a single line for each team, ordering teams as mentioned above. For each team, the line you print should be of the form “ ”. These items should be separated by single spaces. Leave a blank line after the output for each data set.

输入

2
2 1
KASNIA LATVERIA
KASNIA 0 LATVERIA 1
4 6
ENGLAND USA ALGERIA SLOVENIA
ENGLAND 1 USA 1
ALGERIA 0 SLOVENIA 1
SLOVENIA 2 USA 2
ENGLAND 0 ALGERIA 0
SLOVENIA 0 ENGLAND 1
USA 1 ALGERIA 0

输出

Group 1:
LATVERIA 3 1 0 0 1 0
KASNIA 0 0 1 0 0 1

Group 2:
USA 5 1 0 2 4 3
ENGLAND 5 1 0 2 2 1
SLOVENIA 4 1 1 1 3 3
ALGERIA 1 0 2 1 0 2

#include <bits/stdc++.h>
using namespace std;
map<string ,int > mp;
struct p
{
	string name;
	int point,win,lose,draw,score,allow;	
}a[10010];
bool cmp(p x,p y)
{
	if(x.point!=y.point)
	return x.point>y.point;
	else if(x.score-x.allow!=y.score-y.allow)
	return x.score-x.allow>y.score-y.allow;
	else if(x.score!=y.score)
	return x.score>y.score;
	else
	return x.name<y.name;
}
int main()
{
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		mp.clear();
		int n,m;
		cin>>n>>m;
		for(int j=1;j<=n;j++)
		cin>>a[j].name,a[j].point=a[j].win=a[j].lose=a[j].draw=a[j].allow=a[j].score=0,mp[a[j].name]=j;
		
		for(int j=1;j<=m;j++)
		{
			string p1,p2;
			int s1,s2;
			cin>>p1>>s1>>p2>>s2;
			if(s1>s2)
			{
				a[mp[p1]].win++;
				a[mp[p1]].point+=3;
				a[mp[p2]].lose++;
				a[mp[p2]].allow+=s1;
				a[mp[p1]].allow+=s2;
			}
			else if(s1==s2)
			{
				a[mp[p1]].point++;
				a[mp[p2]].point++;
				a[mp[p1]].draw++;
				a[mp[p2]].draw++;
				a[mp[p2]].allow+=s1;
				a[mp[p1]].allow+=s2;
			}
			else
			{
				a[mp[p2]].win++;
				a[mp[p2]].point+=3;
				a[mp[p1]].lose++;
				a[mp[p1]].allow+=s2;
				a[mp[p2]].allow+=s1;
			}
			a[mp[p2]].score+=s2;
			a[mp[p1]].score+=s1;
		}
		sort(a+1,a+n+1,cmp);
		printf("Group %d:\n",i);
		for(int j=1;j<=n;j++)
		cout<<a[j].name<<" "<<a[j].point<<" "<<a[j].win<<" "<<a[j].lose<<" "<<a[j].draw<<" "<<a[j].score<<" "<<a[j].allow<<endl;
		cout<<endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值