/*
* 谢谢好心人呦~,错在分数有可能是两位数!!,要有一个小Judgement
*/
已AC代码!!!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char teamName[ 105 ];
char team[ 35 ][ 35 ];
char situ[ 1000 ][ 150 ];
int win[ 35 ] , tie[ 35 ] , loss[ 35 ],total[ 35 ];
int scored[ 35 ],against[ 35 ];
int vis[ 35 ];
int m,n;
int search( char temp[] )
{
int i;
for(i=0;i<n;i++ )
if( strcmp( team[ i ] , temp ) == 0 )
return i;
return -1;
}
int Goal( int x , int y )
{
if( x > y ) return 1;
if( x == y ) return 0;
if( x < y ) return -1;
}
int Win( int x , int y )
{
if( win[ x ] > win[ y ] ) return 1;
else if( win[ x ] == win[ y ] ) return 0;
else if( win[ x ] < win[ y ] ) return -1;
}
int S_G( int x , int y )
{
if( scored[ x ]-against[ x ] > scored[ y ]-against[ y ] ) return 1;
else if( scored[ x ]-against[ x ] == scored[ y ]-against[ y ] ) return 0;
else if( scored[ x ]-against[ x ] < scored[ y ]-against[ y ] ) return -1;
}
int S( int x , int y )
{
if( scored[ x ] > scored[ y ] ) return 1;
else if( scored[ x ] == scored[ y ] ) return 0;
else if( scored[ x ] < scored[ y ] ) return -1;
}
int Str( int x , int y )
{
if( strcasecmp( team[ x ] , team[ y ] ) < 0 ) return 1;
else return -1;
}
int Find( )
{
int i;
int max = -1,maxPos = -1,tmp;
int xx , yy;
for( i=0;i<n;i++ )
if( total[ i ] > max && !vis[ i ] )
{
max = total[ i ];
maxPos = i;
}
else if( total[ i ] == max && !vis[ i ] )
{
tmp = Win( i , maxPos );
if( tmp == 1 )
{
max = total[ i ];
maxPos = i;
}
else if( tmp==0 )
{
tmp = S_G( i , maxPos );
if( tmp == 1 )
{
max = total[ i ];
maxPos = i;
}
else if( tmp == 0 )
{
tmp = S( i , maxPos );
if( tmp == 1 )
{
max = total[ i ];
maxPos = i;
}
else if( tmp == 0 )
{
xx = win[ i ] + tie[ i ] + loss[ i ];
yy = win[ maxPos ] + tie[ maxPos ] + loss[ maxPos ];
tmp = Goal( xx , yy );
if( tmp == -1 )
{
max = total[ i ];
maxPos = i;
}
else if( tmp == 0 )
{
tmp = Str( i , maxPos );
if( tmp == 1 )
{
max = total[ i ];
maxPos = i;
}
}
}
}
}
}
vis[ maxPos ] = 1;
return maxPos;
}
int main()
{
int t;
int i,j;
int flag,p,x,y,xx,yy,tmp,max;
char temp[ 35 ];
scanf("%d",&t);
getchar();
while( t-- )
{
memset( vis,0,sizeof(vis));
memset( win,0,sizeof(win));
memset( tie,0,sizeof(tie));
memset( loss,0,sizeof(loss));
memset( total,0,sizeof(total));
memset( scored,0,sizeof(scored));
memset( against,0,sizeof(against));
gets( teamName );
scanf("%d",&n);
getchar( );
for( i=0;i<n;i++,p = 0 )
gets( team[ i ] );
scanf("%d",&m);
getchar( );
for( i=0;i<m;i++ )
gets( situ[ i ] );
for( i=0;i<m;i++ )
{
flag = p = j = 0;
while( j < strlen(situ[ i ]) )
{
while( situ[ i ][ j ] != '#' )
temp[ p++ ] = situ[ i ][ j++ ];
temp[ p ] = '\0';
x = search( temp );
xx = situ[ i ][ j+1 ]-'0';
if( isdigit( situ[ i ][ j+2 ] ) )
{
xx = xx*10 + situ[ i ][ j+2 ] -'0';
yy = situ[ i ][ j+4 ]-'0';
if( isdigit( situ[ i ][ j+5 ] ) )
{
yy = yy*10 + situ[ i ][ j+5 ]-'0';
j++;
}
j += 6;
}
else
{
yy = situ[ i ][ j+3 ]-'0';
if( isdigit( situ[ i ][ j+4 ] ) )
{
yy = yy*10 + situ[ i ][ j+4 ] - '0';
j++;
}
j+=5;
}
p = 0;
while( j < strlen(situ[ i ]) )
temp[ p++ ] = situ[ i ][ j++ ];
temp[ p ] = '\0';
y = search( temp );
tmp = Goal( xx , yy );
if( tmp == 1)
{
win[ x ]++;
loss[ y ]++;
total[ x ] += 3;
}
else if( tmp == 0 )
{
tie[ x ]++;
tie[ y ]++;
total[ x ]++;
total[ y ]++;
}
else if( tmp == -1 )
{
loss[ x ]++;
win[ y ]++;
total[ y ] += 3;
}
scored[ x ] += xx;
scored[ y ] += yy;
against[ x ] += yy;
against[ y ] += xx;
}
}
printf("%s\n",teamName);
for( i=0;i<n;i++ )
{
max = Find();
printf("%d) %s %dp, %dg ",i+1,team[ max ],total[ max ],win[max]+tie[max]+loss[max]);
printf("(%d-%d-%d), %dgd (%d-%d)",win[max],tie[max],loss[max],scored[max]-against[max],scored[max],against[max]);
puts("");
}
if( t ) puts("");
}
return 0;
}
下面附上我觉得思路很近的别人AC的代码
摘自http://blog.csdn.net/hcbbt/article/details/10244281
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
struct Table {
int tp, g, w, t, l, h, i;
string n;
}tb[50];
bool cmp(Table a, Table b) {
if (a.tp != b.tp)
return a.tp > b.tp;
if (a.w != b.w)
return a.w > b.w;
if ((a.h - a.i) != (b.h - b.i))
return (a.h - a.i) > (b.h - b.i);
if (a.h != b.h)
return a.h > b.h;
if (a.g != b.g)
return a.g < b.g;
string ta, tb;
for (int i = 0; i < a.n.size(); i++)
ta += toupper(a.n[i]);
for (int i = 0; i < b.n.size(); i++)
tb += toupper(b.n[i]);
return ta < tb;
}
int main() {
int n;
scanf("%d", &n);
getchar();
while (n--) {
string name;
int t, g;
getline(cin, name);
cout << name << endl;
scanf("%d\n", &t);
for (int i = 0; i < t; i++) {
getline(cin, tb[i].n);
tb[i].tp = tb[i].g = tb[i].w = tb[i].t = tb[i].l = tb[i].h = tb[i].i = 0;
}
scanf("%d\n", &g);
for (int i = 0; i < g; i++) {
string t1, t2;
int n1, n2;
int s1, s2;
char tmp;
while ((tmp = getchar()) != '#')
t1 += tmp;
scanf("%d@%d#", &s1, &s2);
getline(cin, t2);
for (int i = 0; i < t; i++)
if (t1 == tb[i].n) {
n1 = i;
break;
}
for (int i = 0; i < t; i++)
if (t2 == tb[i].n) {
n2 = i;
break;
}
// cout << n1 << ' ' << s1 << ' ' << t1 << endl;
// cout << n2 << ' ' << s2 << ' ' << t2 << endl;
tb[n1].g++;
tb[n2].g++;
tb[n1].h += s1;
tb[n1].i += s2;
tb[n2].h += s2;
tb[n2].i += s1;
if (s1 > s2) {
tb[n1].tp += 3;
tb[n1].w++;
tb[n2].l++;
}
else if (s1 < s2) {
tb[n2].tp += 3;
tb[n2].w++;
tb[n1].l++;
}
else {
tb[n1].tp++;
tb[n2].tp++;
tb[n1].t++;
tb[n2].t++;
}
}
sort (tb, tb + t, cmp);
for (int i = 0; i < t; i++) {
printf("%d) ", i + 1);
cout << tb[i].n;
printf(" %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", tb[i].tp, tb[i].g, tb[i].w, tb[i].t, tb[i].l, tb[i].h - tb[i].i, tb[i].h, tb[i].i);
}
if (n)
cout << endl;
}
return 0;
}