您的位置:首页 > 其它

UVa10194 Football (aka Soccer)

2013-08-05 16:40 344 查看


 Problem A: Football (aka Soccer) 

The Problem

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 mostWorld 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 ofstandings with so many teams and games played!

So, your task is quite simple: write a program that receives the tournament name, team namesand 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 gameif 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):

Most points earned.
Most wins.
Most goal difference (i.e. goals scored - goals against)
Most goals scored.
Less games played.
Lexicographic order.

The Input

The first 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
willhave 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 greaterthan or equal to 32 (space), except for '#' and '@' characters, which will never appear in teamnames. 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 forthe number of games already played on this tournament. G will be no greater than 1000. Then, Glines 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.

The Output

For each tournament, you must output the tournament name in a single line. In the next Tlines you must output the standings, according to the rules above. Notice that should thetie-breaker be the lexographic order, it must be done case insenstive. The output
format for each line is shown bellow:

[a]) Team_name 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 fields and a single blank line between output sets. See the sample output for examples.

Sample Input

2
World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway
Some strange tournament
5
Team A
Team B
Team C
Team D
Team E
5
Team A#1@1#Team B
Team A#2@2#Team C
Team A#0@0#Team D
Team E#2@1#Team C
Team E#1@2#Team D

Sample Output

World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4)
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)

Some strange tournament
1) Team D 4p, 2g (1-1-0), 1gd (2-1)
2) Team E 3p, 2g (1-0-1), 0gd (3-3)
3) Team A 3p, 3g (0-3-0), 0gd (3-3)
4) Team B 1p, 1g (0-1-0), 0gd (1-1)
5) Team C 1p, 2g (0-1-1), -1gd (3-4)

[b]© 2001 Universidade do Brasil (UFRJ). Internal Contest 2001.\


这题就是个模拟题,模拟足球比赛结果,要注意的主要就是要排名时,总分、胜场、净胜球数、进球数都是从大到小排序的,场数是按从小到大排序的,字典序不分大小写。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

map<string,int> team;

struct Team{
char name[50];
int points;
int times;
int wins;
int ties;
int losses;
int goal_d;
int goals_s;
int goals_a;
}t[100];

char game[100];

bool cmp(Team a,Team b) {
if (a.points == b.points)
if (a.wins == b.wins)
if (a.goal_d == b.goal_d)
if (a.goals_s == b.goals_s)
if (a.times == b.times) {
for (int i = 0; i < 50; i++) {
if (isupper(a.name[i]))
a.name[i] = tolower(a.name[i]);
if (isupper(b.name[i]))
b.name[i] = tolower(b.name[i]);
}
return strcmp(a.name,b.name) < 0;
}
else
return a.times < b.times;
else
return a.goals_s > b.goals_s;
else
return a.goal_d > b.goal_d;
else
return a.wins > b.wins;
else
return a.points > b.points;
}

int main() {
int t_1;
cin >> t_1;
getchar();
while (t_1--) {
memset(game,0,sizeof(game));
if (!team.empty())
team.clear();
gets(game);
int t_2;
cin >> t_2;
getchar();
memset(t,0,sizeof(t));
for (int i = 0; i < t_2; i++) {
gets(t[i].name);
team[t[i].name] = i;
}
int t_3;
char tmp_1[50];
char tmp_2[50];
int s_1;
int s_2;
char ch;
cin >> t_3;
getchar();
for (int i = 0; i < t_3; i++) {
memset(tmp_1,0,sizeof(tmp_1));
memset(tmp_2,0,sizeof(tmp_2));
int x = 0; //
while (ch = getchar()) {
if ('#' == ch)
break;
tmp_1[x] = ch;
x++;
}
tmp_1[x] = '\0';
scanf("%d",&s_1);
getchar();
scanf("%d",&s_2);
getchar();
gets(tmp_2);

t[team[tmp_1]].times += 1;
t[team[tmp_1]].goal_d += s_1 - s_2;
t[team[tmp_1]].goals_s += s_1;
t[team[tmp_1]].goals_a += s_2;

t[team[tmp_2]].times += 1;
t[team[tmp_2]].goal_d += s_2 - s_1;
t[team[tmp_2]].goals_s += s_2;
t[team[tmp_2]].goals_a += s_1;

if (s_1 > s_2) {
t[team[tmp_1]].points += 3;
t[team[tmp_1]].wins += 1;
t[team[tmp_2]].losses += 1;
}
else if (s_1 == s_2) {
t[team[tmp_1]].points += 1;
t[team[tmp_1]].ties += 1;
t[team[tmp_2]].points += 1;
t[team[tmp_2]].ties += 1;
}
else {
t[team[tmp_2]].points += 3;
t[team[tmp_2]].wins += 1;
t[team[tmp_1]].losses += 1;
}
}
sort(t,t+t_2,cmp);

cout << game << endl;
for (int i = 0; i < t_2; i++) {
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,t[i].name,t[i].points,t[i].times,t[i].wins,t[i].ties,t[i].losses,t[i].goal_d,t[i].goals_s,t[i].goals_a);
}

if (t_1)
cout << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva 算法