首页 > 其他 > 详细

UVA10194 FootBall aka Soccer

时间:2014-02-27 22:59:40      阅读:633      评论:0      收藏:0      [点我收藏+]

这个题自己感觉就是结构体排序的问题 ,不过细节问题好像很多 ,,而且还得把题读得十分明白 ,这种超长的题目,果然还要锻炼自己英语功底 ,那几个足球术语都是海词现查的

今天(应该是昨天了) 没写完 明天(也就是今天) 继续把这个弄完 STL用的不好问题很多

 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)

? 2001 Universidade do Brasil (UFRJ). Internal Contest 2001. 

 

 

bubuko.com,布布扣
  1 /**UVAOJ 10194 对多个项目进行排序**/
  2 #include<iostream>
  3 #include<stdio.h>
  4 #include<set>
  5 #include<string>
  6 #include<algorithm>
  7 using namespace std;
  8 
  9 typedef struct team
 10 {
 11     string name;
 12     //int rank=0;
 13     int points=0;
 14     int played=0;
 15     int wins=0;
 16     int ties = 0;
 17     int lose = 0;                    //输的比赛次数
 18     int losses = 0;                    //输球几个
 19     int differ = 0;
 20     int goals = 0;
 21 
 22 }team;
 23 
 24 bool cmp(const team *a, const team*b)                    //自定义比较函数
 25 {
 26     if (a->points > b->points) return true;
 27     else if (a->points < b->points) return false;
 28     else
 29     {
 30         if (a->wins>b->wins) return true;
 31         else if (a->wins < b->wins) return false;
 32         else
 33         {
 34             if (a->differ>b->differ) return true;
 35             else if (a->differ < b->differ) return false;
 36             else
 37             {
 38                 if (a->goals>b->goals) return true;
 39                 else if (a->goals < b->goals) return false;
 40                 else
 41                 {
 42                     if (a->played<b->played) return true;
 43                     else if (a->played >= b->played) return false;
 44                 }
 45             }
 46         }
 47     }
 48 }
 49 
 50 int main(void)
 51 {
 52     string game;
 53     int matches;
 54     int num;
 55     scanf("%d", &matches);
 56     getchar();
 57     for (int i = 0; i < matches; i++)
 58     {
 59         getline(cin, game);
 60         scanf("%d", &num);
 61         set<team*> T;
 62         for (int oo = 0; oo < num; oo++)
 63         {
 64             string teamtmp;
 65             team *tmp=(team*)malloc(sizeof(team));                    //是不是应该用内存分配?
 66             cin >> teamtmp;
 67             tmp->name = teamtmp;
 68             T.insert(tmp);
 69         }                        //存入各个小组信息
 70         scanf("%d", &num);        //比赛场数
 71         for (int oo = 0; oo < num; oo++)
 72         {
 73             string data;        //读入信息的区域
 74             getline(cin, data);
 75             string cur;
 76             int cnt = 0;
 77             team *curteama,*curteamb;
 78             int scorea = 0 , scoreb = 0;
 79             while (data[cnt] != #) cur += data[cnt++];
 80             for (set<team*>::iterator i = T.begin(); i != T.end(); i++)
 81             if ((*i)->name == cur) curteama = *i;                            //定位到当前队伍a
 82             while (data[cnt] != @)                                        //读取比分 先读 a team
 83             {
 84                 scorea = scorea * 10 + data[cnt] - 0;
 85                 cnt++;
 86             }
 87             cnt++;
 88             while (data[cnt] != #)
 89             {
 90                 scoreb = scoreb * 10 + data[cnt] - 0;                        //再读b team
 91                 cnt++;
 92             }
 93             while (data[cnt] != \0) cur += data[cnt++];
 94             for (set<team*>::iterator i = T.begin(); i != T.end(); i++)        //定位到当前队伍b
 95             if ((*i)->name == cur) curteamb = *i;
 96             //开始判断 并记录
 97             curteama->played += scorea;
 98             curteamb->played += scoreb;
 99             curteama->losses += scoreb;
100             curteamb->losses += scorea;
101             curteama->goals += scorea;
102             curteamb->goals += scoreb;
103             curteama->played++;
104             curteamb->played++;
105             if (scorea > scoreb)                                            //分为a赢了b a b平 a输给 b三种情况
106             {
107                 curteama->wins++;
108                 curteamb->lose++;
109                 curteama->points += 3;
110                 curteamb->points += 0;
111             }
112             else if (scorea < scoreb)
113             {
114                 curteamb->wins++;
115                 curteama->lose++;
116                 curteamb->points += 3;
117                 curteama->points += 0;
118             }
119             else if (scorea == scoreb)
120             {
121                 curteama->ties++;
122                 curteamb->ties++;
123                 curteama->points++;
124                 curteamb->points++;
125             }
126             //判断结束
127             for (set<team*>::iterator i = T.begin(); i != T.end(); i++)
128             {
129                 (*i)->differ = (*i)->goals - (*i)->losses;
130             }
131             //sort(T.begin(), T.end(), cmp);
132             int count = 1;
133             cout << game << endl;
134             for (set<team*>::iterator i = T.begin(); i != T.end(); i++)
135             {
136                 cout << count << ") " << (*i)->name << " " << (*i)->points << "p, " << (*i)->played << "g (" << (*i)->wins << "-" << (*i)->ties << "-" << (*i)->lose << "), " << (*i)->differ << "gd (" << (*i)->goals << "-" << (*i)->losses << ")" << endl;
137             }
138             printf("\n");
139         }
140     }
141     getchar();
142     return 0;
143 }
bubuko.com,布布扣

UVA10194 FootBall aka Soccer,布布扣,bubuko.com

UVA10194 FootBall aka Soccer

原文:http://www.cnblogs.com/VOID-133/p/3570507.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!