zoukankan      html  css  js  c++  java
  • 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('
    ');
            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] = '';
                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] = '';
                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)
    ", 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;
    }
  • 相关阅读:
    WebDev.WebServer使用帮助
    [原创]通过编写PowerDesigner脚本功能批量修改属性
    Web中响应用户修改的事件
    郁闷的切换foxmail
    Java中Split函数的用法技巧
    [转].NET安装项目卸载的方法
    把你的名字刻到IE上
    JavaScript面向对象编程笔记
    附件下载直接显示另存为对话框并保存原有中文文件名的解决办法
    MyEclipse开发JSP页面假死问题解决办法
  • 原文地址:https://www.cnblogs.com/txd0u/p/3392168.html
Copyright © 2011-2022 走看看