HDU1225 Football Score 【结构体排序】

Football Score

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2579    Accepted Submission(s): 729

Problem Description

Football is one of the greatest games in the world. Lots of people like to play football. After one season of matches, the header has to calculate the last scores of every team. He is too lazy that he doesn‘t want to calculate, so
he asks you to write a program for him to solve the problem.

Here are the rules:

1 Every team has to match with all the other teams.

2 Every two teams have to match for two times,one at home and one away.

3 In one match, the winner will get 3 points, the loser will get 0 point. If it is draw, both of them will get 1 point.

Input

The input consists of many test cases. In each case, there will be a number N in the first line which means the number of teams. Followed by N * (N – 1)lines. Each line stands for a match between two teams. The format is: "Team1 VS
Team2 p:q", p stands for the balls that Team1 has kicked in and q stands for the balls that Team2 has kicked in. p and q are not greater than 9.

Process to the end of file.

Output

For each test case, output the teams and their scores in descending order. One line a team, the format is: "TeamX scores". If two teams get the same score, the one with high net goals will be ahead, which net goal means the difference
between the total balls that the team kicked in and the total balls that the team lost. IE: if one team kicked in 30 balls and lost 40 balls, then the net goal is 30 – 40 = -10. If two teams have the same score and the same net goal, the one whose kicked in
balls is bigger will be ahead. If two teams have the same score and the same net goal and the same kicked in balls, they will be outputed in alphabetic order.

Output a blank line after each test case.

Sample Input

3
Manchester VS Portsmouth 3:0
Liverpool VS Manchester 1:1
Liverpool VS Portsmouth 0:0
Portsmouth VS Manchester 1:1
Manchester VS Liverpool 2:1
Liverpool VS Portsmouth 1:2

Sample Output

Manchester 8
Portsmouth 5
Liverpool 2

Hint

Hint

 
Huge input, scanf is recommended.
#include <stdio.h>
#include <string.h>
#include <algorithm>
using std::sort;
struct Node{
	char name[100];
	int win, lost, points, net;
} arr[1000];

int find(char str[], int k){
	for(int i = 0; i < k; ++i)
		if(!strcmp(str, arr[i].name)) return i;
	return -1;
}

bool cmp(Node a, Node b){
	if(a.points > b.points) return true;
	if(a.points == b.points && a.net > b.net) return true;
	if(a.points == b.points && a.net == b.net && a.win > b.win)
		return true;
	if(a.points == b.points && a.net == b.net &&
		a.win == b.win && strcmp(a.name, b.name) < 0)
		return true;
	return false;
}

int main(){
	int n, win, lost, pos, id, sign;
	char name1[100], name2[100];
	while(scanf("%d", &n) == 1){
		id = 0;
		for(int i = 0; i < n * (n - 1); ++i){
			scanf("%s%*s%s %d:%d", name1, name2, &win, &lost);
			sign = win - lost;
			if((pos = find(name1, id)) != -1){
				arr[pos].win += win;
				arr[pos].lost += lost;
				if(sign > 0) arr[pos].points += 3;
				else if(sign == 0) arr[pos].points += 1;
			}else{
				strcpy(arr[id].name, name1);
				arr[id].win = win;
				arr[id].lost = lost;
				if(sign > 0) arr[id].points = 3;
				else if(sign == 0) arr[id].points = 1;
				else arr[id].points = 0;
				++id;
			}
			if((pos = find(name2, id)) != -1){
				arr[pos].win += lost;
				arr[pos].lost += win;
				if(sign < 0) arr[pos].points += 3;
				else if(sign == 0) arr[pos].points += 1;
			}else{
				strcpy(arr[id].name, name2);
				arr[id].win = lost;
				arr[id].lost = win;
				if(sign < 0) arr[id].points = 3;
				else if(sign == 0) arr[id].points = 1;
				else arr[id].points = 0;
				++id;
			}
		}
		for(int i = 0; i < n; ++i)
			arr[i].net = arr[i].win - arr[i].lost;
		sort(arr, arr + n, cmp);
		for(int i = 0; i < n; ++i)
			printf("%s %d\n", arr[i].name, arr[i].points);
		printf("\n");
	}
	return 0;
}

HDU1225 Football Score 【结构体排序】

时间: 2024-10-16 06:42:59

HDU1225 Football Score 【结构体排序】的相关文章

HDU 1084 [What Is Your Grade?] 结构体排序

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084 题目大意:共5道题,N个学生.做出5道满分,0道50分.做出1-4道的同学,若在前50%(向下取整),则获得95.85.75.65,若在后50%则获得90.80.70.60. 关键思想:结构体排序 //结构体排序,考虑边界 #include <iostream> #include <algorithm> #include <cmath> #include <me

HDU 1862 EXCEL排序(结构体排序)

EXCEL排序 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16387    Accepted Submission(s): 6137 Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=1

【转】 从最简单的vector中sort用法到自定义比较函数comp后对结构体排序的sort算法

sort函数在使用中非常好用,也非常简单,而且效率与冒泡或者选择排序不是一个数量级.本文就sort函数在vector中的用法分为sort函数入门用法与自定义comp比较函数比较结构体这两个最基本的功能讲讲其用法: 1.sort入门: 使用sort需要包含algorithm头文件,完整代码如下 #include<iostream> #include<vector> #include<algorithm>//貌似可以不用,但最好加上. using namespace std

C++结构体排序

在C++中,对结构体的排序方式比C语言丰富的多.在C语言中,我们主要是通过qsort进行排序操作(抛开手写排序算法不说). 在C++<algorithm>中,有一个十分强大的排序函数sort,他的内部综合了许多种排序算法,因此非常高效.并且,用它来对结构体排序也十分方便. 先贴一段示例代码: 1 #include <cstdio> 2 #include <queue> 3 #include <vector> 4 #include <algorithm&

结构体排序

经常碰到结构体排序的问题,在此总结一下.以一个简单的例题开始: 例1.有三个人(Person结构体),每个人都有name(string型)和age(int型)两个属性,现在需要按照下面的规则排序:先以姓名按从小到大排序(如abc<abd),如果姓名相同,则按照年龄从大到小排序. #include<iostream> #include<string> using namespace std; struct Person{ string name; int age; }; voi

HDOJ 1009. Fat Mouse&#39; Trade 贪心 结构体排序

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g

最小生成树模板+并查集(隐藏)+结构体排序模板

minn[101],g[101][101],u[101]; memset(u,1,sizeof(u)); memset(minn,0x7f,sizeof(minn)); minn[1]=0; u[1]=0; i,j,k,m; total=0; for(i=1;i<=n;i++) { k=0; for(j=1;j<=n;j++) if(u[j]&&(minn[k]>minn[j])) k=j; u[k]=0; for(j=1;j<=n;j++) if(u[j]&

HDU 2409 Team Arrangement (结构体排序)

题目链接:HDU 2409 Team Arrangement 题意:给出22个人(编号,名字,踢的位置,在队里的时间),让我们选DD-MM-SS的阵型+一个守门员.在选出队长(时间在最久的就是队长,时间相同编号大为队长),选人的顺序是从编号小的开始. 结构体排序就好了,注意出输出是按队长,D,M,S的顺序,选队长记录队长的编号(而不是下标,我的代码之后还要排序). AC代码: #include<stdio.h> #include<string.h> #include<algo

CodeForces 151 B 结构体排序。

E - 结构体又来了呦 Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 151B Description Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order