#include #include #define MAX_NAME 101 #define MAX_TEAMS 80 typedef struct { int first, second; } match_t; typedef struct { char name[ MAX_NAME ]; int matches, won, tied, lost, scores, goals, points; } team_t; void addmatch( int teamnum, team_t *teams, match_t matches[ MAX_TEAMS ][ MAX_TEAMS ] ) { char first[ MAX_NAME ], second[ MAX_NAME ]; int score, goal, i, fidx, sidx; scanf( "%s - %s %d:%d ", first, second, &score, &goal ); fidx = sidx = -1; for( i = 0; i < teamnum; i++ ) { if( fidx < 0 && !strcmp( first, teams[ i ].name ) ) { fidx = i; } if( sidx < 0 && !strcmp( second, teams[ i ].name ) ) { sidx = i; } if( fidx >= 0 && sidx >= 0 ) { break; } } matches[ fidx ][ sidx ].first = score; matches[ fidx ][ sidx ].second = goal; teams[ fidx ].matches++; teams[ sidx ].matches++; teams[ fidx ].scores += score; teams[ fidx ].goals += goal; teams[ sidx ].scores += goal; teams[ sidx ].goals += score; if( score > goal ) { teams[ fidx ].won++; teams[ sidx ].lost++; teams[ fidx ].points += 3; } else if( score < goal ) { teams[ fidx ].lost++; teams[ sidx ].won++; teams[ sidx ].points += 3; } else { teams[ fidx ].tied++; teams[ sidx ].tied++; teams[ fidx ].points++; teams[ sidx ].points++; } } int cmp( const team_t *first, const team_t *second ) { int tmp1, tmp2; if( first->points != second->points ) { return first->points - second->points; } tmp1 = first->scores - first->goals; tmp2 = second->scores - second->goals; if( tmp1 != tmp2 ) { return tmp1 - tmp2; } if( first->scores != second->scores ) { return first->scores - second->scores; } return first->won - second->won; } void bogosort( team_t teams[ MAX_TEAMS ], int teamnum, int idxtab[ MAX_TEAMS ] ) { int i, j, min, tmp; for( i = 0; i < teamnum; i++ ) { min = i; for( j = i+1; j < teamnum; j++ ) { if( cmp( teams + idxtab[min], teams + idxtab[j] ) > 0 ) { min = j; } } tmp = idxtab[ i ]; idxtab[ i ] = idxtab[ min ]; idxtab[ min ] = tmp; } } void printsep( int teams, int maxlen ) { int i; printf( "+" ); for( i = 0; i < maxlen; i++ ) { printf( "-" ); } for( i = 0; i < teams; i++ ) { printf( "+" ); printf( "---" ); } printf( "+\n" ); } void printline( team_t teams[ MAX_TEAMS], match_t matches[ MAX_TEAMS ][ MAX_TEAMS ], int teamnum, int idx, int maxlen ) { int i; printf( "|%s", teams[ idx ].name ); for( i = maxlen - strlen( teams[ idx ].name ); i; i-- ) { printf( " " ); } printf( "|" ); for( i = teamnum -1; i >= 0; i-- ) { if( i == idx ) { printf( " X |" ); continue; } if( matches[idx][ i ].first < 0 ) { printf( " |" ); continue; } printf( "%d:%d|", matches[idx][i].first, matches[idx][i].second ); } printf( "\n" ); } void printres( int teamnum, team_t *teams, match_t matches[ MAX_TEAMS ][ MAX_TEAMS ], int idxtab[ MAX_TEAMS ], int maxlen ) { int i, j; printsep( teamnum, maxlen ); printf( "|" ); for( i = 0; i < maxlen; i++ ) { printf( " " ); } for( i = teamnum - 1; i >= 0; i-- ) { printf( "|" ); for( j = 0; j < 3; j++ ) { putchar( teams[ i ].name[j] ); } } printf( "|\n" ); printsep( teamnum, maxlen ); for( i = teamnum - 1; i >= 0; i-- ) { printline( teams, matches, teamnum, i, maxlen ); printsep( teamnum, maxlen ); } printf( "\nSTANDINGS:\n----------\n" ); for( i = teamnum - 1; i >=0; i-- ) { printf( "%d. %s", teamnum-i, teams[ idxtab[i] ].name ); for( j = maxlen - strlen( teams[ idxtab[i] ].name ); j; j-- ) { printf( " " ); } printf( " %d %d %d %d %d:%d %d\n", teams[idxtab[i]].matches, teams[idxtab[i]].won, teams[idxtab[i]].tied, teams[idxtab[i]].lost, teams[idxtab[i]].scores, teams[idxtab[i]].goals, teams[idxtab[i]].points ); } } int main( int argc, char **argv ) { team_t teams[ MAX_TEAMS ]; match_t matches[ MAX_TEAMS ][ MAX_TEAMS ]; int indextab[ MAX_TEAMS ]; int teamnum, matchnum, i, j, tmp, maxlen = 0; scanf( "%d ", &teamnum ); while( teamnum ) { for( i = teamnum - 1; i >= 0; i-- ) { scanf( "%s ", teams[ i ].name ); tmp = strlen( teams[ i ].name ); maxlen = maxlen > tmp ? maxlen : tmp; indextab[ i ] = i; teams[i].matches = 0; teams[i].won = 0; teams[i].tied = 0; teams[i].lost = 0; teams[i].scores = 0; teams[i].goals = 0; teams[i].points = 0; } for( i = 0; i < teamnum; i++ ) { for( j = 0; j < teamnum; j++ ) { matches[ i ][ j ].first = -1; matches[ i ][ j ].second = -1; } } scanf( "%d ", &matchnum ); for( i = 0; i < matchnum; i++ ) { addmatch( teamnum, teams, matches ); } bogosort( teams, teamnum, indextab ); printres( teamnum, teams, matches, indextab, maxlen ); printf( "\n" ); scanf( "%d ", &teamnum ); } return 0; }