UVA 10194 Football (aka Soccer)
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):
- 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 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)
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char cn[105];
int tnum;
int cnum;
int tt;
struct Team
{
char name[35];
int f;
int z;
int y;
int s;
int p;
int zq;
int yq;
int sq;
} t[35]; int find(char *team)
{
for (int i = 0; i < tnum; i ++)
{
if(strcmp(t[i].name, team) == 0)
{
return i;
}
}
return -1;
} int cmp(Team a, Team b)
{
if (a.f == b.f)
{
if (a.y == b.y)
{
if (a.zq == b.zq)
{
if (a.yq == b.yq)
{
if (a.z == b.z)
{
if (strcasecmp(a.name, b.name) < 0)
return 1;
if (strcasecmp(a.name, b.name) > 0)
return 0;
}
else
return a.z < b.z;
}
else
return a.yq > b.yq;
}
else
return a.zq > b.zq;
}
else
return a.y > b.y;
}
else
return a.f > b.f;
} int main()
{
scanf("%d", &tt);
getchar();
while (tt --)
{
gets(cn);
memset(t, 0, sizeof(t));
scanf("%d", &tnum);
getchar();
for (int i = 0; i < tnum; i ++)
gets(t[i].name);
scanf("%d", &cnum);
getchar();
while (cnum --)
{
char t1[35];
int t1num = 0;
int t1y = 0;
char t2[35];
int t2num = 0;
int t2y = 0;
char sb;
while ((sb = getchar()) != EOF)
{
if (sb == '#')
break;
t1[t1num ++] = sb;
}
t1[t1num] = '\0';
while ((sb = getchar()) != EOF)
{
if (sb == '@')
break;
t1y = t1y * 10 + sb - '0';
}
while ((sb = getchar()) != EOF)
{
if (sb == '#')
break;
t2y = t2y * 10 + sb - '0';
}
while ((sb = getchar()) != EOF)
{
if (sb == '\n')
break;
t2[t2num ++] = sb;
}
t2[t2num] = '\0';
int t11 = find(t1);
int t22 = find(t2);
t[t11].yq += t1y;
t[t11].sq += t2y;
if (t1y > t2y)
t[t11].y ++;
else if(t1y < t2y)
t[t11].s ++;
else
t[t11].p ++;
t[t22].yq += t2y;
t[t22].sq += t1y;
if (t1y > t2y)
t[t22].s ++;
else if(t1y < t2y)
t[t22].y ++;
else
t[t22].p ++;
}
for (int i = 0; i < tnum; i ++)
{
t[i].f = t[i].y * 3 + t[i].p;
t[i].z = t[i].y + t[i].p + t[i].s;
t[i].zq = t[i].yq - t[i].sq;
}
sort(t, t + tnum, cmp);
printf("%s\n", cn);
for (int i = 0; i < tnum; i ++)
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i + 1, t[i].name, t[i].f, t[i].z, t[i].y, t[i].p, t[i].s, t[i].zq, t[i].yq, t[i].sq);
if (tt)
printf("\n");
}
return 0;
}
UVA 10194 Football (aka Soccer)的更多相关文章
- D - Football (aka Soccer)
Football the most popular sport in the world (americans insist to call it "Soccer", but we ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. Sorting/Searching(uva)
340 - Master-Mind Hints /*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次. 题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 3(Sorting/Searching)
第一题:340 - Master-Mind Hints UVA:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Item ...
- (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO
http://www.cnblogs.com/sxiszero/p/3618737.html 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年 ...
- ACM训练计划step 1 [非原创]
(Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO 下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成 ...
- 算法竞赛入门经典+挑战编程+USACO
下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...
- Randy Pausch’s Last Lecture
he University of Virginia American Studies Program 2002-2003. Randy Pausch ...
随机推荐
- jdk环境变量配置(总结)
进行java开发,首先要安装jdk,安装了jdk后还要进行环境变量配置: 1.下载jdk(http://java.sun.com/javase/downloads/index.jsp),我下载的版本是 ...
- 搭建mysql主从复制---Mysql Replication
主从复制原理 Mysql的Replication是一个异步的复制过程,从一个Mysql Instance(master)复制到另一个Mysql Instance(slave).中间需要三个线程slav ...
- 重构技巧 引入Null对象
描述:有两个类,学生类和导师类,学生的导师类可能不存在,因此在获取学生导师名字等信息时都要先判断导师名字是否为空.重构后通过一个空导师类来处理导师为空的相应逻辑. Before # introduce ...
- 006 Python的操作符
算术操作符: + - * / % ** // 如 >>> a = 5 >>> a = a + 3 >>&g ...
- Poco之ftp目录切换与创建
TEMPLATE = app QT += qml quick widgets#LIBS += -lPocoFoundation -lPocoXML -lPocoNetSOURCES += main.c ...
- qt 5 基础知识 2(控件篇)
QVBoxLayout *lay = new QVBoxLayout(this); // 创建一个竖直的盒子 lebel 篇 lay->addWidget(label = new QLabel( ...
- 第 11 章 桥梁模式【Bridge Pattern】
以下内容出自:<<24种设计模式介绍与6大设计原则>> 今天我要说说我自己,梦想中的我自己,我身价过亿,有两个大公司,一个是房地产公司,一个是服装制造业,这两个公司都很赚钱,天 ...
- 把内表 itab1 的 n1 到 n2 行内容附加到 itab2 内表中去.
语法:append lines of itab1 [ from n1 ] [ to n2 ] to itab2. DATA:BEGIN OF gt_00 OCCURS 0, l_01 ...
- Logstash同步Oracle数据到ElasticSearch
最近在项目上应用到了ElasticSearch和Logstash,在此主要记录了Logstash-input-jdbc同步Oracle数据库到ElasticSearch的主要步骤,本文是对环境进行简单 ...
- 【网络流24题】No. 13 星际转移问题 (网络判定 最大流)
[题意] 由于人类对自然资源的消耗, 人们意识到大约在 2300 年之后, 地球就不能再居住了.于是在月球上建立了新的绿地,以便在需要时移民. 令人意想不到的是, 2177 年冬由于未知的原因, 地球 ...