UVA 10194 - Football (aka Soccer)

题目大意:有n组样例,每组样例有m支球队,每支球队有名字。然后之间发生了x场比赛,每场比赛对阵双方,进球数。赢得比赛队伍+3分,输比赛不加分,平局加一分。按排名输出结果(队名,)。排名按照优先级为:总分数  > 赢得场数  > 净进球数(总进球数-总输球数)  >  总进球数 > 总场数  > 队名。总分数高,赢得场数多,净进球数多,总进球数多,总场数少,队名(全部小写以后的)字典次序小。

解题思路:定义一个结构体,包括球队所有信息,队名,总分数,比赛总情况(赢,输,平),总场数,进球,被进球,净进球数,队名化为小写以后的名字。读取比赛情况字符串内的对阵双方,球数,根据球数判断输赢,已经进球数,被进球数。最后写一个按照优先级排的比较函数,比较一下就可以了。题目内容比较多,难度不难,麻烦一些。定义为全局变量可以少些挺多代码,但是我就不。

#include <iostream>
#include <cstring>
#include <algorithm> 
using namespace std;
struct node{
	char name[100];
	int score;
	int count[3];
	int C; 
	int gold[2];
	int G;
	char little[100];
};
void little_write(char a[], char b[])
{
	strcpy(a, b);
	int len=strlen(a);
	for (int i=0; i<len; i++)
		if (a[i] >= 'A' && a[i] <='Z')
			a[i] += 32;
}

bool compare(node &a, node &b)
{
	a.C = a.count[0]+a.count[1]+a.count[2];
	b.C = b.count[0]+b.count[1]+b.count[2];
	a.G = a.gold[0]-a.gold[1];
	b.G = b.gold[0]-b.gold[1];
	if (a.score != b.score)
		return (a.score > b.score);
	if (a.count[0] != b.count[0])
		return (a.count[0] > b.count[0]);
	if (a.G != b.G)
		return (a.G > b.G);
	if (a.gold[0] != b.gold[0])
		return (a.gold[0] > b.gold[0]);
	if (a.C != b.C)
		return (a.C < b.C);
	if (strcmp(a.little, b.little) < 0)
		return 1;
	return 0;
}

void add(int &a, int &b, int c)
{
	a += c;
	b += c;
}
void count_gold(int &j, char c[], int &go)
{
	j++;
	for (int tt=1; c[j]>='0' && c[j]<='9'; tt=10,j++)		
		go = go * 10+c[j]-'0';
}
int main()
{
	int n, m1, m2, len, len2, so1, so2, go1, go2;
	char game[100], c[100];
	char temp1[100], temp2[100];
	node a[5000];
	int temp3, temp4;
	cin >> n;	
	getchar();
	while (n--){
		gets(game);
		cin >> m1;
		getchar();
		for (int i=0; i<m1; i++){
			gets(a[i].name);
			little_write(a[i].little, a[i].name);
			a[i].count[0] = a[i].count[1] = a[i].count[2] = 0;
			a[i].gold[0] = a[i].gold[1] = a[i].score= 0;
		}	
		cin >> m2;
		getchar();
		for (int i=0; i<m2; i++){
			gets(c);
			len = strlen(c);
			go1 = go2 = 0;
			for (int j=0; j<len; j++){
				if (!j){
					for (int k=0; c[j]!='#'; k++,j++){
						temp1[k] = c[j];
						temp1[k+1] = '\0';
					}
					count_gold(j, c, go1);
					count_gold(j, c, go2);
				}
				len2 = strlen(c);
				if (c[j] == '#'){
					j++;
					for (int k=0; k<len; k++,j++){
						temp2[k] = c[j];
						temp2[k+1] = '\0';						
					}
				}
				for (int k=0; k<m1; k++){
					if (!strcmp(temp1, a[k].name))
						temp3 = k;
					if (!strcmp(temp2, a[k].name))
						temp4 = k;
				}	
				add(a[temp3].gold[0], a[temp4].gold[1], go1);
				add(a[temp3].gold[1], a[temp4].gold[0], go2);
				if (go1 == go2){
					a[temp3].count[1]++;
					a[temp4].count[1]++;
					a[temp3].score++;
					a[temp4].score++;
				}
				else if (go1 > go2){
					a[temp3].count[0]++;
					a[temp4].count[2]++;
					a[temp3].score+=3;	
				}
				else{
					a[temp3].count[2]++;
					a[temp4].count[0]++;
					a[temp4].score+=3;
				}		
			}
		}
		sort(a, a+m1, compare);
		printf("%s\n", game);
		for (int i=0; i<m1; i++){
			printf("%d) %s %dp, %dg (%d-%d-", i+1, a[i].name, a[i].score, a[i].C, a[i].count[0], a[i].count[1]);
			printf("%d), %dgd (%d-%d)\n",  a[i].count[2], a[i].G, a[i].gold[0], a[i].gold[1]);
		}		
		if (n)
			cout << endl;
	} 
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值