UVA10194

思路:模拟题。。不过有些麻烦。。

            排名规则要处理好,特别是最后两条,前一个是场次少的排在前面,后面一个是要按字典序排列,不分大小写。。。我就是在这个地方WA了好多次。。。。无奈。。

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

struct Team{
	Team(){	
	 	point = 0;
	 	play = 0;
	 	win = 0;
	 	ties = 0;
	 	loss = 0;
	 	difference = 0;
	 	score = 0;
	 	against = 0;	
	}
	int point;
	int play;
	int win;
	int ties;
	int loss;
	int difference;
	int score;
	int against;
	char name1[50];
	char name2[50];
};

int cmp(void const *a, void const *b){
	struct Team * c = (Team *)a;	
	struct Team * d = (Team *)b;
	if (c -> point != d -> point)
		return d -> point - c -> point;
	if (c -> win != d -> win)
		return d -> win - c -> win;
	if (c -> difference != d -> difference)
		return d -> difference - c -> difference;
	if (c -> score != d -> score)
		return d -> score - c -> score;
	if (c -> play != d -> play)
		return c -> play - d -> play;
	return strcmp(c -> name2, d -> name2);	
}

int main(){
	int cas, n, m;	
	char s[110];	
	scanf("%d", &cas);
	getchar();
	while (cas--){
		gets(s);	
		scanf("%d", &n);	
		Team team[1000];
		getchar();	
		for(int i = 0; i < n; i++){
			gets(team[i].name1);
			for(int j = 0; j < strlen(team[i].name1); j++)	
				team[i].name2[j] =	tolower(team[i].name1[j]); 
			team[i].name2[strlen(team[i].name1)] = '\0';
		}	
		scanf("%d", &m);
		getchar();
		while (m--){	
			int cnt = 0;
			char t1[50], t2[50], ch;
			while (ch = getchar(), ch != '#')
				t1[cnt++] = ch;	
			t1[cnt] = '\0';	
			int a, b;		
			scanf("%d", &a);
			getchar();
			scanf("%d", &b);
			getchar();
			gets(t2);
			for(int i = 0; i < n; i++){
				if (strcmp(team[i].name1, t1) == 0){
					if (a > b){				
						team[i].point += 3;
						team[i].difference += (a - b);
						team[i].win++;	
					}
					else if (a == b){
						team[i].point += 1;
						team[i].ties++;	
					}
					else{
						team[i].loss++;
						team[i].difference += (a - b);
					}
					team[i].play++;	
					team[i].score += a;
					team[i].against += b;
				}		
				if (strcmp(team[i].name1, t2) == 0){
					if (b > a){				
						team[i].point += 3;	
						team[i].difference += (b - a);
						team[i].win++;	
					}
					else if (a == b){
						team[i].point += 1;
						team[i].ties++;	
					}
					else{
						team[i].loss++;	
						team[i].difference += (b - a);
					}
					team[i].play++;		
					team[i].score += b;
					team[i].against += a;
				}		
			}	
		}
		qsort(team, n, sizeof(team[0]), cmp);
		puts(s);
		for(int i = 0; i < n; i++){
			printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, team[i].name1, team[i].point, team[i].play, 
					team[i].win, team[i].ties, team[i].loss, team[i].difference, team[i].score, team[i].against);		
		}
		if (cas)
		printf("\n");
	}
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值