Uva 10194 Football (aka Soccer)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1135

 

有点繁琐,2A。

按照题目描述的排序即可。

 

# include <stdio.h>
# include <ctype.h>
# include <string.h>
# include <stdlib.h>

struct team{
    char name[35];
    char mname[35];
    int played_games;
    int points;
    int wins;
    int ties;
    int loses;
    int goals;
    int goals_against;
};

int n;
char tournament_name[105];
int T;
team a[35];
int G;

int r[35];
char game[1005];
/*
    Most points earned.
    Most wins.
    Most goal difference (i.e. goals scored - goals against)
    Most goals scored.
    Less games played.
    Lexicographic order. 
*/
int play(team *x, team *y)
{
    if (x->points == y->points) {
        if (x->wins == y->wins) {
            int xgd = x->goals - x->goals_against;
            int ygd = y->goals - y->goals_against;
            if (xgd == ygd) {
                if (x->goals == y->goals) {
                    if (x->played_games == y->played_games) {
                        return strcmp(x->mname, y->mname);
                    }
                    else return x->played_games - y->played_games;
                }
                else return y->goals - x->goals;
            }
            else return ygd - xgd;
        }
        else return y->wins - x->wins;
    }
    else return y->points - x->points;
}

int icmp(const void *x, const void *y)
{
    int xx = *(int *)x;
    int yy = *(int *)y;
    return play(&a[xx], &a[yy]);
}

int find(char *str) {
    for (int i = 1; i <= T; ++i) {
        if (strcmp(str, a[i].name) == 0) return i;
    }
    return 0;
}

int main()
{
    char tmp[10];
    scanf("%d", &n); gets(tmp);
    for (int i = 0; i < n; ++i) {
        if (i) putchar('\n');
        gets(tournament_name);
        puts(tournament_name);
        scanf("%d", &T); gets(tmp);
        for (int i = 1; i <= T; ++i) r[i] = i;
        for (int i = 1; i <= T; ++i) {
            gets(a[i].name);
            for (int j = 0; a[i].name[j]; ++j) {
                if (isalpha(a[i].name[j])) a[i].mname[j] = tolower(a[i].name[j]);
                else a[i].mname[j] = a[i].name[j];
            }
            a[i].played_games = 0;
            a[i].points = 0;
            a[i].wins = a[i].ties = a[i].loses = 0;
            a[i].goals = 0;
            a[i].goals_against = 0;
        }
        scanf("%d", &G); gets(tmp);
        char buffer[35];
        for (int k, i = 1; i <= G; ++i) {
            gets(game);
            for (k = 0; game[k] != '#'; ++k) buffer[k] = game[k]; buffer[k] = '\0';
            int ta = find(buffer);
            int x, y;
            char ch;
            char *p = game + k + 1;
            sscanf(p, "%d%c%d", &x, &ch, &y);
            while (*p != '#') ++p;
            ++p;
            for (k = 0; p[k]; ++k) buffer[k] = p[k]; buffer[k] = '\0';
            int tb = find(buffer);
            ++a[ta].played_games;
            ++a[tb].played_games;
            a[ta].goals += x;
            a[ta].goals_against += y;
            a[tb].goals += y;
            a[tb].goals_against += x;
            if (x > y) {
                a[ta].points += 3;
                ++a[ta].wins;
                ++a[tb].loses;
            } else if (x < y) {
                a[tb].points += 3;
                ++a[tb].wins;
                ++a[ta].loses;
            } else {
                ++a[ta].points;
                ++a[tb].points;
                ++a[ta].ties;
                ++a[tb].ties;
            }
        }
        qsort(r+1, T, sizeof(r[0]), icmp);
        for (int i = 1; i <= T; ++i) {
            int k = r[i];
            printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i, a[k].name, a[k].points, a[k].played_games, a[k].wins, a[k].ties, a[k].loses, a[k].goals-a[k].goals_against, a[k].goals, a[k].goals_against);
        }
    }
    
    return 0;
}

 

转载于:https://www.cnblogs.com/txd0u/p/3392168.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值