ZOJ 2524- Football Match (模拟+map)

Description

Today football has become the most popular sport all over the world. Many countries have their own football league matches. And the FIFA wants to hold a great league match which could contains all the clubs throughout the world. It is difficult to rank so many teams just by hand. So they come to you for help.

The rules of ranking are:
1. A team will get 3 points when they win a match, 1 point when get a draw, 0 point when lost.
2. Teams are ranked by their total points first. If two teams have the same points, the team who get the more "goal difference" ranks higher. "Goal difference" for a team is equal to the total number of balls they goal minus those they lost.
3. If two teams have both the same points and the same "goal difference", ranking them by their name alphabetically.

Input

The input contains many cases. The beginning of each case is a num m (m<=10000), which is the number of matches. The following m lines each give a score of a match. The format is:
Team_name1 score1:score2 Team_name2
The length of team name is no more than 20 characters and the scores are less than 100. You may assume that every team in the league has taken part in at least one match.

Output

For each case output a ranking table, each team a line. The format of each line is
Id Nm w d l Pt Gd
"Id" is the index of the team starting from 1. "Nm" is the name of the team. "w", "d" and "l" respectively is the total number of matches the team win, draw and lost. "Pt" is the points of the team. And "Gd" is the team's goal difference.
Use a single blank to separate all cases.

Sample Input

4
Liverpool 1:0 ManchesterU
ManchesterU 3:0 Leeds
Arsenal 2:2 Liverpool
Leeds 1:5 Arsenal
6
RealMadrid 3:2 ACMilan
ZJGreenCity 3:2 RealMadrid
ACMilan 1:4 ZJGreenCity
RealMadrid 0:0 ZJGreenCity
ACMilan 2:0 RealMadrid
ZJGreenCity 3:3 ACMilan

Sample Output

1 Arsenal 1 1 0 4 4
2 Liverpool 1 1 0 4 1
3 ManchesterU 1 0 1 3 2
4 Leeds 0 0 2 0 -7

1 ZJGreenCity 2 2 0 8 4
2 ACMilan 1 1 2 4 -2
3 RealMadrid 1 1 2 4 -2

                                                                                        

模拟+map

CODE:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
const int inf=0xfffffff;
typedef long long ll;
using namespace std;
struct contest
{
    string nl;
    string nr;
    int pl,pr;
}con[10004];
struct team
{
    string name;
    int win,pin,lost,pwin,plost,sum,g;
}t[10004];
map<int,string>m;
map<string,int>mm;

bool cmp(team a,team b)
{
    if(a.sum==b.sum){
        if(a.g==b.g) return a.name<b.name;
        return a.g>b.g;
    }
    return a.sum>b.sum;
}

int main()
{
    //freopen("in","r",stdin);
    int M;
    int m_=0;
    while(~scanf("%d",&M)){
        if(m_!=0) cout<<endl;
        m_++;
        getchar();
        int q=1;
        char ch;
        for(int i=0;i<M;i++){
            cin>>con[i].nl>>con[i].pl;
            cin>>ch;
            cin>>con[i].pr>>con[i].nr;
            if(mm[con[i].nl]==0){
                mm[con[i].nl]=q;
                m[q]=con[i].nl;
                q++;
            }
            if(mm[con[i].nr]==0){
                mm[con[i].nr]=q;
                m[q]=con[i].nr;
                q++;
            }
        }
        for(int i=1;i<q;i++){
            t[i].name=m[i];
            t[i].g=0;  t[i].lost=0;  t[i].pin=0;
            t[i].plost=0; t[i].win=0; t[i].pwin=0;
            t[i].sum=0;
        }

        int id;
        for(int i=0;i<M;i++){
            if(con[i].pl>con[i].pr){ //左边赢了
                id=mm[con[i].nl];
                t[id].name=con[i].nl;
                t[id].win++;
                t[id].pwin+=(con[i].pl-con[i].pr);

                id=mm[con[i].nr];
                t[id].lost++;
                t[id].plost+=(con[i].pl-con[i].pr);
            }

            if(con[i].pl<con[i].pr){//右边赢了
                id=mm[con[i].nr];
                t[id].win++;
                t[id].pwin+=(con[i].pr-con[i].pl);

                id=mm[con[i].nl];
                t[id].lost++;
                t[id].plost+=(con[i].pr-con[i].pl);
            }

            if(con[i].pl==con[i].pr){
                id=mm[con[i].nl];
                t[id].pin++;

                id=mm[con[i].nr];
                t[id].pin++;
            }
        }
        for(int i=1;i<q;i++){
            t[i].sum=t[i].win*3+t[i].pin;
            t[i].g=t[i].pwin-t[i].plost;
        }
        sort(t+1,t+q,cmp);
        for(int i=1;i<q;i++){
            cout<<i<<" "<<t[i].name<<" "<<t[i].win<<" "<<t[i].pin<<" "<<t[i].lost<<" "<<t[i].sum<<" "<<t[i].g<<endl;
        }

    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值