Question: give you some game records of the team and sort the team's scores.
Analysis: simulation. Follow the meaning of the question to simulate.
Sorting Priority: 1. High scores, 2. many victories, 3. Many victories, 4. Many goals, 5. Fewer matches, and 6. Lexicographic orders of team names.
Note: The team name is case insensitive, that is, the team name is considered to be the same.
#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;}