Football (aka Soccer)



Football (aka Soccer)

Football the most popular sport in the world (americans insist to call it \Soccer", but we will call
it \Football"). As everyone knows, Brasil is the country that have most World Cup titles (four of
them: 1958, 1962, 1970 and 1994). As our national tournament have many teams (and even regional
tournaments have many teams also) it's a very hard task to keep track of standings with so many teams
and games played!
So, your task is quite simple: write a program that receives the tournament name, team names and
games played and outputs the tournament standings so far.
A team wins a game if it scores more goals than its oponent. Obviously, a team loses a game if it
scores less goals. When both teams score the same number of goals, we call it a tie. A team earns 3
points for each win, 1 point for each tie and 0 point for each loss.
Teams are ranked according to these rules (in this order):
1. Most points earned.
2. Most wins.
3. Most goal difference (i.e. goals scored - goals against)
4. Most goals scored.
5. Less games played.
6. Lexicographic order.
Input

The rst line of input will be an integer N in a line alone (0 < N < 1000). Then, will follow N
tournament descriptions. Each one begins with the tournament name, on a single line. Tournament
names can have any letter, digits, spaces etc. Tournament names will have length of at most 100.
Then, in the next line, there will be a number T (1 < T 30), which stands for the number of teams
participating on this tournament. Then will follow T lines, each one containing one team name. Team
names may have any character that have ASCII code greater than or equal to 32 (space), except for
`#' and `@' characters, which will never appear in team names. No team name will have more than 30
characters.
Following to team names, there will be a non-negative integer G on a single line which stands for
the number of games already played on this tournament. G will be no greater than 1000. Then, G
lines will follow with the results of games played. They will follow this format:
team name 1#goals1@goals2#team name 2
For instance, the following line:
Team A#3@1#Team B
Means that in a game between Team A and Team B, Team A scored 3 goals and Team B scored
1.
All goals will be non-negative integers less than 20. You may assume that there will not be inexistent
team names (i.e. all team names that appear on game results will have apperead on the team names
section) and that no team will play against itself.

Output
For each tournament, you must output the tournament name in a single line. In the next T lines you
must output the standings, according to the rules above. Notice that should the tie-breaker be the
lexographic order, it must be done case insenstive. The output format for each line is shown bellow:
[a]) Team name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])
Where:
[a] = team rank
[b] = total points earned
[c] = games played
[d] = wins
[e] = ties
[f] = losses
[g] = goal difference
[h] = goals scored
[i] = goals against
There must be a single blank space between elds and a single blank line between output sets. See
the sample output for examples.

大意:

题目给出比赛名称,队伍数量,赛事情况,让你统计各个队伍的排名情况

要点:

进球和被进球如果用字符串接受,要特别处理;

判断排名的六个条件中,第五个要求最少的比赛场次,第6个要求队名字典序最小,但是不区分大小写;

每个测试中间要有一行空白,最后一个测试输出完直接结束;

代码:

#include <stdio.h>
#include <string.h>

struct team{
	char name[35];
	int point;
	int win;
	int ties;
	int losses;
	int goalsscored;
	int goalsagainst;
};

int lwr(char *s1, char *s2)
{
	char x1[35];
	char x2[35];
	int count = 0;
	for (int i = 0; i < strlen(s1); i++){
		if (s1[i] >= 'A' && s1[i] <= 'Z'){
			x1[i] = s1[i] + 32;
			count++;
		}
		else{
			x1[i] = s1[i];
			count++;
		}
	}
	x1[count] = '\0';
	count = 0;
	for (int i = 0; i < strlen(s2); i++){
		if (s2[i] >= 'A' && s2[i] <= 'Z'){
			x2[i] = s2[i] + 32;
			count++;
		}
		else{
			x2[i] = s2[i];
			count++;
		}
	}
	if (strcmp(x1, x2) > 0)
		return 1;
	else
		return 0;
}

void match(char *game, int teamnum, struct team *t){

	char tname1[35], tname2[35];
	int score1 = 0, score2 = 0;
	bool f1, f2, f3;
	f1 = f2 = f3 = true;
	int j = 0;
	for (int i = 0; i < strlen(game); i++){
		if (game[i] != '#' && f1 && f2 && f3){
			tname1[j] = game[i];
			j++;
		}
		else if (game[i] == '#' && f1 && f2 && f3){
			tname1[j] = '\0';
			f1 = false;
		}
		else if (game[i] != '@' && !f1 && f2 && f3){
			score1 = score1 * 10 + game[i] - '0';
		}
		else if (game[i] == '@' && !f1 && f2 && f3){
			f2 = false;
		}
		else if (game[i] != '#' && !f1 && !f2 && f3){
			score2 = score2 * 10 + game[i] - '0';
		}
		else if (game[i] == '#' && !f1 && !f2 && f3){
			f3 = false;
			j = 0;
		}
		else if (!f1 && !f2 && !f3){
			tname2[j] = game[i];
			j++;
		}
	}
	tname2[j] = '\0';
	
	for (int i = 0; i < teamnum; i++){
		if (!strcmp(t[i].name, tname1)){
			t[i].goalsscored += score1;
			t[i].goalsagainst += score2;
			if (score1 > score2){
				t[i].point += 3;
				t[i].win++;
			}
			else if (score1 == score2){
				t[i].point += 1;
				t[i].ties++;
			}
			else {
				t[i].losses++;
			}
		}
		if (!strcmp(t[i].name, tname2)){
			t[i].goalsscored += score2;
			t[i].goalsagainst += score1;
			if (score1 < score2){
				t[i].point += 3;
				t[i].win++;
			}
			else if (score1 == score2){
				t[i].point += 1;
				t[i].ties++;
			}
			else {
				t[i].losses++;
			}
		}
	}

}

void print(int teamnum, struct team *t){
	struct team tx;
	for (int i = 0; i < teamnum - 1; i++){
		for (int j = i + 1; j < teamnum; j++){
			if (t[i].point < t[j].point){
				tx = t[i];
				t[i] = t[j];
				t[j] = tx;
				continue;
			}
			else if (t[i].point > t[j].point)
				continue;
			else {
				if (t[i].win < t[j].win){
					tx = t[i];
					t[i] = t[j];
					t[j] = tx;
					continue;
				}
				else if (t[i].win > t[j].win)
					continue;
				else {
					if (t[i].goalsscored - t[i].goalsagainst < t[j].goalsscored - t[j].goalsagainst){
						tx = t[i];
						t[i] = t[j];
						t[j] = tx;
						continue;
					}
					else if (t[i].goalsscored - t[i].goalsagainst > t[j].goalsscored - t[j].goalsagainst)
						continue;
					else {
						if (t[i].goalsscored < t[j].goalsscored){
							tx = t[i];
							t[i] = t[j];
							t[j] = tx;
							continue;
						}
						else if (t[i].goalsscored > t[j].goalsscored)
							continue;
						else {
							if (t[i].win + t[i].losses + t[i].ties > t[j].win + t[j].losses + t[j].ties){
								tx = t[i];
								t[i] = t[j];
								t[j] = tx;
								continue;
							}
							else if (t[i].win + t[i].losses + t[i].ties < t[j].win + t[j].losses + t[j].ties)
								continue;
							else {
								if ((lwr(t[i].name, t[j].name))){
									tx = t[i];
									t[i] = t[j];
									t[j] = tx;
									continue;
								}
							}
						}
					}
				}
			}
		}
	}
}

int main(){

	int n; 
	scanf ("%d\n", &n);

	char tournament[105];
	struct team t[35];
	int teamnum;

	while (n--){
		char c;
		int x = 0;
		while ((c = getchar()) != '\n'){
			tournament[x] = c;
			x++;
		}
		tournament[x] = '\0';
		
		scanf ("%d\n", &teamnum);
		int r = teamnum;
		int q, w;
		q = 0;
		while (r--){
			w = 0;
			while ((c = getchar()) != '\n'){
				t[q].name[w] = c;
				w++;
			}
			t[q].name[w] = '\0';
			t[q].goalsagainst = t[q].goalsscored = t[q].losses = 
				t[q].point = t[q].ties = t[q].win = 0;
			q++;
		}
		int gameplay;
		scanf("%d\n", &gameplay);
		while (gameplay--){
			char game[80];
			x = 0;
			while ((c = getchar()) != '\n'){
				game[x] = c;
				x++;
			}
			game[x] = '\0';
			match(game, teamnum, t);
		}

		print(teamnum, t);

		printf("%s\n", tournament);
		for (int i = 0; i < teamnum; i++){
			int g = t[i].win + t[i].losses + t[i].ties;
			int gd = t[i].goalsscored - t[i].goalsagainst;
			printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, t[i].name, t[i].point, g, t[i].win, t[i].ties, 
				t[i].losses, gd, t[i].goalsscored, t[i].goalsagainst);
		}
		if (n)
			printf("\n");
	}
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值