Soccer Standings(c++)

Soccer Standings(c++),第1张

Soccer Standings(c++)

Soccer Standings (足球排名)(c++)

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 “name points wins losses draws goals _scored goals _allowed”. These items should be separated by single spaces. Leave a blank line after the output for each data set.

### 输入样例:

```in

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


```

### 输出样例:```out

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

思路:
       跳过无关紧要的英文描述,直接看问题,扑捉一下文中的英文关键词,不必全都翻译,如果还是看不懂,可以结合样例去理解。
eg: In the event of a tie结合上下文或样例可以推测出意思为平局。

        由于本题中各个变量存在一定逻辑关系,所以设置一个结构体会方便。

#include

using namespace std;

struct number{

	string name;//队名
	int score; //得分
	int win; //赢局数
	int failure;//输局数
	int ping;//平局数
	int jing;
	int get;//进球次数
	int lose;//失球次数
};//结构体
	
bool cmb(struct number x,struct number y) //仿函数
{
	if((x.score==y.score)&&(x.jing!=y.jing))
		return x.jing>y.jing;
	if((x.jing==y.jing)&&(x.get!=y.get))
		return x.get>y.get;
	if(x.get==y.get)
		return x.name[0]y.score;
}

struct competion
{
	string name1;
	int grade;
};              //存储每一个输入行的:country_1 score_1

int main()
{	
	int w;
	cin>>w;   //确定输入几组数据;
	int k;
	for(int h=1;h<=w;h++)
	{
		struct number dui[1000];    //创建数据类型为number的一个数组
		k=0;//dui【】的长度
		struct number p1;         //创建一个空对象
		p1.failure=0;p1.get=0;p1.lose=0;
		p1.name="";p1.ping=0;p1.score=0;
		p1.win=0;
		struct competion a,b; //比赛中得分 
		string j;
		int t,g;//队伍数,比赛的局数
		cin>>t>>g;
		for(int i=0;i>j;
			p1.name=j;
			dui[k++]=p1;
		}		//在dui数组中记录队名
		while(g--)                //每局比赛,在队中查找与之匹配的队名,并将各种值赋给它
		{
			int index1=-1,index2=-1;
			cin>>a.name1>>a.grade;
			cin>>b.name1>>b.grade;
			for(int i=0;ib.grade)
			{
				dui[index1].score+=3;	
				dui[index1].win++;
				dui[index2].failure++;
			}
			else if(a.grade 

题中排序可以用sort函数排序,不过要写到一个仿函数,确认排序顺序(多个排序顺序的写法值得注意,易写错),注意if函数里的条件,不要少考虑情况。

bool cmb(struct number x,struct number y)
{
	if((x.score==y.score)&&(x.jing!=y.jing))
		return x.jing>y.jing;
	if((x.jing==y.jing)&&(x.get!=y.get))
		return x.get>y.get;
	if(x.get==y.get)
		return x.name[0]y.score;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5699352.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存