UVa 10194 - Football (aka Soccer)

來源:互聯網
上載者:User

標籤:blog   get   2014   os   name   for   

題目:給你一些球隊的比賽記錄,對球隊的成績進行排序。

分析:類比。按照題意類比即可。

            排序優先順序:1.分數高 ,2.勝場多,3.淨勝球多,4.進球多,5.比賽場次少,6.隊名字典序。

注意:隊名大小寫不敏感,即大小寫認為是相同的。

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;char title[104],name[104];typedef struct node{    char  word[32];    int   point,games,wins,losses,scored,against;}list;list dict[32];int small( char c ) {if ( c >= 'A' && c <= 'Z' )return c-'A'+'a';return c;}bool cmpstr( char* a,char* b ){int now = 0;while ( small(a[now]) == small(b[now]) )now ++;return small(a[now]) < small(b[now]);}bool cmp( list a, list b ){if ( a.point != b.point )return a.point > b.point;if ( a.wins != b.wins )return a.wins > b.wins;if ( a.scored-a.against != b.scored-b.against )return a.scored-a.against > b.scored-b.against;if ( a.scored != b.scored )return a.scored > b.scored;if ( a.games != b.games )return a.games < b.games;return cmpstr( a.word, b.word );}int find( char* word, int l, int n ) {    for ( int i,j = 0 ; j < n ; ++ j ) {        for ( i = 0 ; i < l ; ++ i )        if ( small(dict[j].word[i]) != small(word[i]) ) break;        if ( i == l ) return j;    }return -1;}void deal( int T ){int save = 0,s1,s2,t1,t2;    while ( (name[save] = getchar()) != '#' ) save ++;t1 = find( name, save, T );scanf("%d",&s1);getchar();scanf("%d",&s2);getchar();save = 0;    while ( (name[save] = getchar()) != '\n' ) save ++;t2 = find( name, save, T );dict[t1].games ++;dict[t1].scored += s1;dict[t1].against += s2;dict[t2].games ++;dict[t2].scored += s2;dict[t2].against += s1;if ( s1 > s2 ) {dict[t1].point += 3;dict[t1].wins ++;dict[t2].losses ++;}if ( s1 < s2 ) {dict[t2].point += 3;dict[t2].wins ++;dict[t1].losses ++;}if ( s1 == s2 ) {dict[t1].point ++;dict[t2].point ++;}}int main(){    int  N,T,G;    scanf("%d",&N);    getchar();while ( N -- ) {memset( dict, 0, sizeof(dict) );gets(title);    printf("%s\n",title);        scanf("%d",&T);getchar();    for ( int i = 0 ; i < T ; ++ i )         gets(dict[i].word);            scanf("%d",&G);    getchar();    for ( int i = 0 ; i < G ; ++ i ) {        deal( T );}        sort( dict, dict+T, cmp );for ( int i = 0 ; i < T ; ++ i )printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,dict[i].word,dict[i].point,dict[i].games,dict[i].wins,dict[i].games-dict[i].wins-dict[i].losses,dict[i].losses,dict[i].scored-dict[i].against,dict[i].scored,dict[i].against);if ( N ) printf("\n");}    return 0;}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.