Football (aka Soccer) -uva10194 模拟题

简单的模拟,不过超级麻烦、、、注意字典序排序的时候是对大小写不敏感的,一开始因为这个点被卡了好几次。。。。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAX_SIZE 1000 + 100
#define MAXD 1000 + 20
using namespace std;
struct Team
{
    char name[MAX_SIZE];/*球队名字*/
    int score;/*积分*/
    int win; /*胜利场数*/
    int lose;/*失败场数*/
    int tie; /*平均场次*/
    int player;/*总共比赛场次*/
    int Get;/*得球*/
    int Lost;/*失球*/
    int Get_Lost;/*得球-失球*/
};
void  str_str(char x[]){  /*转化大小写*/
    for(int i=0;i<strlen(x);i++){
        if(x[i]>='a'&&x[i]<='z')
            x[i]-=32;
    }
}
bool cmp(Team x,Team y){
    if(x.score<y.score)
        return false;
    if(x.score>y.score)
        return true;
    if(x.win<y.win)
        return false;
    if(x.win>y.win)
        return true;
    if(x.Get_Lost<y.Get_Lost)
        return false;
    if(x.Get_Lost>y.Get_Lost)
        return true;
    if(x.Get<y.Get)
        return false;
    if(x.Get>y.Get)
        return true;
    if(x.player<y.player)
        return true;
    if(x.player>y.player)
        return false;
    str_str(x.name);
    str_str(y.name);
    if(strcmp(x.name,y.name)>0)
        return false;
    else
        return true;
}
int main(){
    int N;
    scanf("%d",&N);
    getchar();
    for(int cases=1;cases<=N;cases++){
        char GameName[MAX_SIZE];
        char Name[MAX_SIZE];
        Team team[MAXD];
        int  n;
        gets(GameName);
        scanf("%d",&n);/*队伍个数*/
        getchar();
        for(int i=0;i<n;i++){/*加名字顺便初始化*/
            gets(Name);
            strcpy(team[i].name,Name);
            team[i].win   =0;  /*胜利场数*/
            team[i].lose  =0;  /*失败场数*/
            team[i].tie   =0;  /*平均场次*/
            team[i].player=0;  /*总共比赛场次*/
            team[i].Get   =0;  /*得球*/
            team[i].Lost  =0;  /*失球*/
        }
        int m;
        scanf("%d",&m);/*输入比赛的场次*/
        getchar();
        char Game[MAX_SIZE];
        for(int i=0;i<m;i++){
            memset(Game,0,sizeof(Game));
            gets(Game);
            /*先提取得分*/
            char *p1=strchr(Game,'#');
            char *p2=strchr(Game,'@');
            char *p3=strchr(p1+1,'#');
            int point1;
            int point2;
            sscanf(p1+1,"%d",&point1);
            sscanf(p2+1,"%d",&point2);
            /*已经将分数提取出来了*/
            *p1='\0';
            /*队名也提取完毕了*/
            /*下面开始找队伍*/
            int x;int y;/*记录队伍*/
            for(int i=0;i<n;i++){
                if(strcmp(Game,team[i].name)==0)
                    x=i;
                else if(strcmp(p3+1,team[i].name)==0)
                    y=i;
            }
            /*下面判断情况*/
            if(point1>point2){
                team[x].win++;
                team[y].lose++;
            }
            else if(point1<point2){
                team[x].lose++;
                team[y].win ++;
            }
            else if(point1==point2){
                team[x].tie++;
                team[y].tie++;
            }
            team[x].Get +=point1;
            team[x].Lost+=point2;
            team[x].player++;
            team[y].Get +=point2;
            team[y].Lost+=point1;
            team[y].player++;
        }
        for(int i=0;i<n;i++){
            team[i].score=3*team[i].win+1*team[i].tie;
            team[i].Get_Lost=team[i].Get-team[i].Lost;
        }
        sort(team,team+n,cmp);
        printf("%s\n",GameName);
        for(int i=0;i<n;i++)
        printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,team[i].name,team[i].score,team[i].player,team[i].win,team[i].tie,team[i].lose,team[i].Get_Lost,team[i].Get,team[i].Lost);
        if(cases<N)
        printf("\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值