首页 > 代码库 > UVa 10194 - Football (aka Soccer)

UVa 10194 - Football (aka Soccer)

题目:给你一些球队的比赛记录,对球队的成绩进行排序。

分析:模拟。按照题意模拟即可。

            排序优先级: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;
}