貌似就是排序。。。。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define N 2000 struct tt { int score,net_goal,total_ball; char team[N]; } a[N]; char stra[N],strb[N],c[3],d; char team[N][200]; bool cmp(tt a,tt b) { if(a.score==b.score) { if(a.net_goal==b.net_goal) { if(a.total_ball==b.total_ball) return strcmp(a.team,b.team)==-1; return a.total_ball>b.total_ball; } return a.net_goal>b.net_goal; } return a.score>b.score; } int main() { int i,j,t,p,q,k; while(~scanf("%d",&t)) { k=0; int n=t*(t-1); memset(a,0,sizeof(a)); while(n--) { int ok=0,index; scanf("%s %s %s %d%c%d",stra,c,strb,&p,&d,&q); for(i=0;i<k;i++) if(strcmp(stra,a[i].team)==0) {ok=1;index=i;break;} if(ok) { a[index].net_goal+=p-q; a[index].total_ball+=p; if(p>q){ a[index].score+=3; } else if(p==q) a[index].score+=1; } else{ strcpy(a[i].team,stra); a[k].net_goal+=p-q; a[k].total_ball+=p; if(p>q) a[k].score+=3; else if(p==q) a[k].score+=1; k++; } ok=0; for(i=0;i<k;i++) if(strcmp(strb,a[i].team)==0) {ok=1;index=i;break;} if(ok) { a[index].net_goal+=q-p; a[index].total_ball+=q; if(p<q){ a[index].score+=3; } else if(p==q) a[index].score+=1; } else{ strcpy(a[i].team,strb); a[k].net_goal+=q-p; a[k].total_ball+=q; if(p<q) a[k].score+=3; else if(p==q) a[k].score+=1; k++; } } sort(a,a+t,cmp); for(i=0;i<t;i++) printf("%s %d ",a[i].team,a[i].score); printf(" "); } return 0; }