您的位置:首页 > 其它

UVA 10194 Football (aka Soccer)

2014-04-23 16:43 483 查看



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)


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

很简单却很烦的字符串处理题目,给出若干球队和比赛结果,要你做出最后的积分榜。

球迷请自动忽略以下信息:

胜平负积分分别为3,1,0;

积分榜的排名标准:

1.积分

2.获胜场次

3.净胜球

4.进球数

5.更少的场次

6.队名的字典序(尼玛这里忽略大小写f**k)

这里当心漏条件

读入数据有点麻烦,注意格式控制,使用STL会方便很多

输出注意最后一组数据后不要空行

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define LL long long
#define INF 0x3f3f3f3f
#define PI 3.14159265358979
#define eps 1e-10
#define mm

using namespace std;

int n,m;
char c;
string matchname;
string temp;
map<string,int>MAP;
struct team
{
    string name;
    int pts,t,win,tie,lose,goal,lost;
    void clear ()
    {
        pts=t=win=tie=lose=goal=lost=0;
    }
}te[33];

bool cmp(const team &x,const team &y)
{
    if (x.pts==y.pts)
    {
        if (x.win==y.win)
        {
            if (x.goal-x.lost==y.goal-y.lost)
            {
                if (x.goal==y.goal)
                {
                    if (x.t==y.t)
                    {
                        string t1,t2;
                        for (int i=0;i<x.name.size();i++)
                                t1+=tolower(x.name[i]);
                        for (int i=0;i<y.name.size();i++)
                                t2+=tolower(y.name[i]);

                        return t1<t2;
                    }
                    return x.t<y.t;
                }
                return x.goal>y.goal;
            }
            return (x.goal-x.lost)>(y.goal-y.lost);
        }
        return x.win>y.win;
    }
    return x.pts>y.pts;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("t","r",stdin);
    #endif

	int tt,cc=0;
	scanf("%d",&tt);getchar();

	while (tt--)
    {
        MAP.clear();

        if (cc) puts("");
        cc++;

        matchname="";
        while (c=getchar(),c!='\n')
            matchname+=c;
        printf("%s\n",matchname.c_str());

        scanf("%d",&n);getchar();
        for (int i=0;i<n;i++)
        {
            temp="";
            while (c=getchar(),c!='\n')
                temp+=c;
            MAP[temp]=i;
            te[i].clear();
            te[i].name=temp;

        }

        scanf("%d",&m);getchar();

        for (int i=0;i<m;i++)
        {

            string t1,t2;
            int p1,p2;
            while (c=getchar(),c!='#')
                t1+=c;
            scanf("%d@%d#",&p1,&p2);
            while (c=getchar(),c!='\n')
                t2+=c;

            te[MAP[t1]].t++;
            te[MAP[t1]].goal+=p1;
            te[MAP[t1]].lost+=p2;
            te[MAP[t2]].t++;
            te[MAP[t2]].goal+=p2;
            te[MAP[t2]].lost+=p1;
            if (p1==p2)
            {
                te[MAP[t1]].pts++;  te[MAP[t1]].tie++;
                te[MAP[t2]].pts++;  te[MAP[t2]].tie++;

            }
            else
            {
                if (p1>p2)
                {
                    te[MAP[t1]].pts+=3;     te[MAP[t1]].win++;
                    te[MAP[t2]].lose++;
                }
                else
                {
                    te[MAP[t2]].pts+=3;     te[MAP[t2]].win++;
                    te[MAP[t1]].lose++;
                }
            }

        }

        sort(te,te+n,cmp);

        for (int i=0;i<n;i++)
        {
            printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,te[i].name.c_str(),te[i].pts,
                   te[i].t,te[i].win,te[i].tie,te[i].lose,te[i].goal-te[i].lost,te[i].goal,te[i].lost);
        }
    }

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