map+string容器的应用(D题Football Match)

来源:互联网 发布:软件开发就业前景 编辑:程序博客网 时间:2024/06/05 21:03

问题 D : Football Match

时间限制:2 秒
内存限制:32 兆
特殊判题: 否
提交:0
解决: 0

题目描述

如今,足球已经成为了全世界最受欢迎的运动。许多国家都有自己的足球职业联赛。FIFA计划邀请各国的俱乐部组成一个大型的国际联赛,但手动排名毕竟太麻烦了。于是他们找到了你。

排名规则如下:

1. 一队如赢得一场比赛积3分,平一场积1分,负一场积0分。

2. 首先,队伍按总积分排序。如果两个队伍积分相同,则净胜球多的队排在前面。净胜球数为总进球数减去总失球数。

3. 如果两个队伍有相同的积分以及净胜球数,那么将按他们的名字升序排列。

输入格式

输入数据第一行包含一个整数m(m<=10000),表示比赛场数。其后m行每行给出一场比赛的信息。格式如下:

队名得分1:得分队名2

其中队名不超过20个字符,得分不超过100。假定任何联赛队伍都至少参加了一场比赛。

输出

输出相应的排名表,一行一个队伍。格式如下:

Id Nm w d l Pt Gd

"Id"是队伍的编号,从1开始。"Nm" 是队名。"w", "d"  "l" 分别表示这个队伍的胜场数,平场数,负场数。"Pt"表示队伍积分。"Gd"表示队伍净胜球数。

样例输入

4
Liverpool 1:0 ManchesterU
ManchesterU 3:0 Leeds
Arsenal 2:2 Liverpool
Leeds 1:5 Arsenal

样例输出

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

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>#include<string>#include<map>using namespace std;const int N=10010;struct team{    string name;    int w,d,l,pt,gd;} t[N];bool cmp(team a,team b){    if(a.pt==b.pt)    {        if(a.gd==b.gd)            return a.name<b.name;        return a.gd>b.gd;    }    return a.pt>b.pt;}int n,cnt;map<string,int> Map;int get_num(string s)//返回每个人对应结点{    if(Map.find(s)==Map.end())//没有搜索到该键值    {        Map[s]=cnt;        t[cnt].name=s;        t[cnt].w=t[cnt].d=t[cnt].l=t[cnt].pt=t[cnt].gd=0;        cnt++;    }    return Map[s];}int main(){    //freopen("C:\\Users\\Administrator\\Desktop\\kd.txt","r",stdin);    while(~scanf("%d",&n))    {        int x1,x2;        cnt=0;        string str1,str2;        for(int i=0; i<n; i++)        {            char ch;            cin>>str1>>x1>>ch>>x2>>str2;            //scanf("%s%d:%d%s",s1,&x1,&x2,s2);            int x=get_num(str1);            int y=get_num(str2);            t[x].gd+=(x1-x2);            t[y].gd+=(x2-x1);            if(x1==x2)            {                t[x].d++;                t[x].pt++;                t[y].d++;                t[y].pt++;            }            else if(x1>x2)            {                t[x].w++;                t[x].pt+=3;                t[y].l++;            }            else if(x1<x2)            {                t[y].w++;                t[y].pt+=3;                t[x].l++;            }        }        sort(t,t+cnt,cmp);        for(int i=0; i<cnt; i++)        {            cout<<i+1<<" "<<t[i].name<<" "<<t[i].w<<" "<<t[i].d<<" "<<t[i].l<<" "<<t[i].pt<<" "<<t[i].gd<<endl;        }    }    return 0;}