Football Score
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4502 Accepted Submission(s): 1293
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.
Author
Gao Bo
Source
问题描述:(略)
问题分析:
这个题就是按照足球小组赛的积分规则计算积分,并且按照积分从大到小输出积分。简单题不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* HDU1225 Football Score */
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
const int N = 1e5 + 10;
struct Node {
string name;
int s1; // 积分
int s2; // 净胜球数
int s3; // 进球数
} a[N];
bool cmp(Node x, Node y)
{
if(x.s1 != y.s1)
return x.s1>y.s1; // 积分
if(x.s2 != y.s2)
return x.s2 > y.s2; // 净胜球数
if(x.s3 != y.s3)
return x.s3>y.s3; // 进球数
return x.name < y.name; // 名字字典序
}
int main()
{
int n;
while(cin>>n){
for(int i=1; i <= n; i++)
a[i].s1 = a[i].s2 = a[i].s3=0;
map<string,int>m;
int id=0;
for(int i = 1; i <= n * (n - 1); i++) {
string team1, vs, team2;
char c;
int p, q;
cin >> team1 >> vs >> team2 >> p >> c >> q;
if(m[team1] == 0) {
m[team1] = ++id;
a[id].name = team1;
}
a[m[team1]].s2 += p - q;
a[m[team1]].s3 += p;
if(m[team2] == 0) {
m[team2] = ++id;
a[id].name = team2;
}
a[m[team2]].s2 += q - p;
a[m[team2]].s3 += q;
if(p > q)
a[m[team1]].s1 += 3;
else if(p == q) {
a[m[team1]].s1 += 1;
a[m[team2]].s1 += 1;
} else if(p < q)
a[m[team2]].s1 += 3;
}
sort(a + 1, a + n + 1, cmp);
for(int i = 1; i <= n; i++)
cout << a[i].name << " " << a[i].s1 << endl;
cout << endl;
}
return 0;
}