现在的位置: 首页 > 综合 > 正文

uva 10194 – Football (aka Soccer)

2013年08月09日 ⁄ 综合 ⁄ 共 5767字 ⁄ 字号 评论关闭

 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 most World 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 of standings with so many teams and games played!

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

  1. Most points earned.
  2. Most wins.
  3. Most goal difference (i.e. goals scored - goals against)
  4. Most goals scored.
  5. Less games played.
  6. 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
will have 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 greater than or equal to 32 (space), except for '#' and '@' characters, which will never appear in team names. 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 for the number of games already played on this tournament. G will be no greater than 1000. Then, G lines 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 T lines you must output the standings, according to the rules above. Notice that should the tie-breaker be the lexographic order, it must be done case insenstive. The
output format for each line is shown bellow:

[a]) Team_name [b]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)

简单模拟有点烦

字符读入处理+多关键字排序;

由于球队最多只有30个冒泡之,比较的条件比较复杂,根据题目给的有很多条件,就是最后一个按字典排序不分大小写和最后一个不换行注意即可。

#include <stdio.h>
#include <string.h>
struct football
{char name[31];
 int  a[10];  //1point,2game,3win,4tie,5loss,6score,7against;
}team[31];
int ok(int n,int m)
{if (team[n].a[1]<team[m].a[1]) return 1;
 if (team[n].a[1]>team[m].a[1]) return 0;//POINTS相同才会执行下面否则返回
 if (team[n].a[3]<team[m].a[3]) return 1;
 if (team[n].a[3]>team[m].a[3]) return 0//POINTS 和GAME相同才会执行下面,以下同理,
 if ((team[n].a[6]-team[n].a[7])<(team[m].a[6]-team[m].a[7])) return 1;
 if ((team[n].a[6]-team[n].a[7])>(team[m].a[6]-team[m].a[7])) return 0;
 if (team[n].a[6]<team[m].a[6]) return 1;
 if (team[n].a[6]>team[m].a[6]) return 0;
 if (team[n].a[2]>team[m].a[2]) return 1;
 if (team[n].a[2]<team[m].a[2]) return 0;
 char s1[31],s2[31];
 int i,l;
 l=strlen(team[n].name); s1[l]='\0';
 for (i=0;i<l;i++)
 if (team[n].name[i]<='Z') s1[i]=team[n].name[i]+32;
                      else s1[i]=team[n].name[i];
 l=strlen(team[m].name); s2[l]='\0';
 for (i=0;i<l;i++) 
 if (team[m].name[i]<='Z') s2[i]=team[m].name[i]+32;
                      else s2[i]=team[m].name[i];
 if (strcmp(s1,s2)>0) return 1;
 if (strcmp(s1,s2)<0) return 0;
 return 0;
};
void main()
{char tour[100],s[200],team1[100],team2[100];
 int n,m,i,j,k,l,num1,num2,pos1,pos2,t;
 scanf("%d\n",&t);
 while (t--)
 {
 gets(tour);
 scanf("%d\n",&n);
 for (i=1;i<=n;i++)
 {gets(team[i].name);
  for (j=1;j<=7;j++)
  team[i].a[j]=0;
 }
 scanf("%d\n",&m);
 while (m--)
 {gets(s);
  j=0; num1=0; num2=0;
  while (s[j]!='#') {team1[j]=s[j];++j;}
  team1[j]='\0';++j;
  while (s[j]!='@') {num1=10*num1+s[j]-'0';++j;}
 
  while (s[j+1]!='#') {++j;num2=10*num2+s[j]-'0';}
  j=j+2;i=j;
  while (s[j]!='\0') {team2[j-i]=s[j];++j;}
  team2[j-i]='\0';
  for (i=1;i<=n;i++)
  {if (strcmp(team1,team[i].name)==0) pos1=i;
   if (strcmp(team2,team[i].name)==0) pos2=i;
  }
  ++team[pos1].a[2];++team[pos2].a[2];
  team[pos1].a[6]+=num1; team[pos1].a[7]+=num2;
  team[pos2].a[6]+=num2; team[pos2].a[7]+=num1;
  if (num1>num2)  {team[pos1].a[1]+=3;team[pos1].a[3]+=1;team[pos2].a[5]+=1;}
  if (num1==num2) {team[pos1].a[1]+=1;team[pos2].a[1]+=1;team[pos1].a[4]+=1;team[pos2].a[4]+=1;}
  if (num1<num2)  {team[pos2].a[1]+=3;team[pos1].a[5]+=1;team[pos2].a[3]+=1;}
 }
 for (i=1;i<n;i++)
 for (j=i+1;j<=n;j++)
 if (ok(i,j))
 {strcpy(team[0].name,team[i].name);
  strcpy(team[i].name,team[j].name);
  strcpy(team[j].name,team[0].name);
  for (k=1;k<=7;k++)
  {m=team[i].a[k];team[i].a[k]=team[j].a[k];team[j].a[k]=m;}
 }
 puts(tour);
 for (i=1;i<=n;i++)
 {printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i,team[i].name,team[i].a[1],team[i].a[2],
  team[i].a[3],team[i].a[4],team[i].a[5],team[i].a[6]-team[i].a[7],team[i].a[6],team[i].a[7]);
 }
 if (t) printf("\n");
 }
}

抱歉!评论已关闭.