UVa:10194 - Football (aka Soccer)
2014-05-30 19:10
330 查看
以下有两组代码,一组AC了,一组没AC,两者差别这在记录队名和得分的算法,但输入样例后结果都是对的。想了很久还是没能想明白没AC的那组代码错哪儿了,一直处于待处理状态。难道是sscanf函数的问题?以前这样用过也没出现过问题啊~~~~思考中……
Code AC:
Code Not AC:
--------------------------------------------------------------------------------------------
Keep It Simple,Stupid!
--------------------------------------------------------------------------------------------
Code AC:
#include<stdio.h> #include<string.h> #include<algorithm> #include<ctype.h> using namespace std; char toun[110]; struct Team{ char name[50]; int b,c,d,e,f,g,h,i; }; Team team[50]; bool cmp(Team x, Team y) { if(x.b==y.b){ if(x.d==y.d){ if(x.g==y.g){ if(x.h==y.h){ if(x.c==y.c){ int lx=strlen(x.name); int ly=strlen(y.name); for(int i=0;i<lx;i++) x.name[i]=tolower(x.name[i]); for(int i=0;i<ly;i++) y.name[i]=tolower(y.name[i]); return strcmp(x.name,y.name)<0; } return x.c<y.c; } return x.h>y.h; } return x.g>y.g; } return x.d>y.d; } return x.b>y.b; } int main() { int N,T,G; scanf("%d",&N); getchar(); while(N--){ gets(toun); scanf("%d",&T); getchar(); for(int i=0;i<T;i++){ gets(team[i].name); team[i].b=team[i].c=team[i].d=team[i].e=team[i].f=team[i].g=team[i].h=team[i].i=0; } scanf("%d",&G); getchar(); while(G--){ char A[50],B[50],ch; int sa,sb,t=0; while (ch = getchar()) { if ('#' == ch) break; A[t] = ch; t++; } A[t]='\0'; scanf("%d",&sa); getchar(); scanf("%d",&sb); getchar(); gets(B); int x,y; for(int j=0;j<T;j++){ if(strcmp(team[j].name,A)==0) x=j; if(strcmp(team[j].name,B)==0) y=j; } if(sa>sb){ team[x].b+=3; team[x].d++; team[y].f++; } if(sa==sb){ team[x].b+=1; team[x].e++; team[y].b+=1; team[y].e++; } if(sa<sb){ team[y].b+=3; team[y].d++; team[x].f++; } team[x].c++; team[x].h+=sa; team[x].i+=sb; team[y].c++; team[y].h+=sb; team[y].i+=sa; } for(int i=0;i<T;i++) team[i].g=team[i].h-team[i].i; sort(team,team+T,cmp); printf("%s\n",toun); for(int i=0;i<T;i++) printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,team[i].name,team[i].b,team[i].c,team[i].d,team[i].e,team[i].f,team[i].g,team[i].h,team[i].i); if(N) printf("\n"); } return 0; }
Code Not AC:
#include<stdio.h> #include<string.h> #include<algorithm> #include<ctype.h> using namespace std; char toun[110]; char game[1010]; struct Team{ char name[50]; int b,c,d,e,f,g,h,i; }; Team team[50]; bool cmp(Team x, Team y) { if(x.b==y.b){ if(x.d==y.d){ if(x.g==y.g){ if(x.h==y.h){ if(x.c==y.c){ int lx=strlen(x.name); int ly=strlen(y.name); for(int i=0;i<lx;i++) x.name[i]=tolower(x.name[i]); for(int i=0;i<ly;i++) y.name[i]=tolower(y.name[i]); return strcmp(x.name,y.name)<0; } return x.c<y.c; } return x.h>y.h; } return x.g>y.g; } return x.d>y.d; } return x.b>y.b; } int main() { int N,T,G; scanf("%d",&N); getchar(); while(N--){ gets(toun); scanf("%d",&T); getchar(); for(int i=0;i<T;i++){ gets(team[i].name); team[i].b=team[i].c=team[i].d=team[i].e=team[i].f=team[i].g=team[i].h=team[i].i=0; } scanf("%d",&G); getchar(); while(G--){ gets(game); char A[50],B[50],na[5],nb[5]; int len=strlen(game); int t=0; for(int j=0;j<len;j++){ if(game[j]=='#'){ A[t]='\0'; t=0; for(int k=j+1;k<len;k++){ if(game[k]=='@'){ na[t]=='\0'; t=0; for(int x=k+1;x<len;x++){ if(game[x]=='#'){ nb[t]='\0'; t=0; for(int y=x+1;y<len;y++) B[t++]=game[y]; B[t]='\0'; break; } nb[t++]=game[x]; } break; } na[t++]=game[k]; } break; } A[t++]=game[j]; } int sa,sb; sscanf(na,"%d",&sa); sscanf(nb,"%d",&sb); int x,y; for(int j=0;j<T;j++){ if(strcmp(team[j].name,A)==0) x=j; if(strcmp(team[j].name,B)==0) y=j; } if(sa>sb){ team[x].b+=3; team[x].d++; team[y].f++; } if(sa==sb){ team[x].b+=1; team[x].e++; team[y].b+=1; team[y].e++; } if(sa<sb){ team[y].b+=3; team[y].d++; team[x].f++; } team[x].c++; team[x].h+=sa; team[x].i+=sb; team[y].c++; team[y].h+=sb; team[y].i+=sa; } for(int i=0;i<T;i++) team[i].g=team[i].h-team[i].i; sort(team,team+T,cmp); printf("%s\n",toun); for(int i=0;i<T;i++) printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,team[i].name,team[i].b,team[i].c,team[i].d,team[i].e,team[i].f,team[i].g,team[i].h,team[i].i); if(N) printf("\n"); } return 0; }
--------------------------------------------------------------------------------------------
Keep It Simple,Stupid!
--------------------------------------------------------------------------------------------
相关文章推荐
- uva 10194 Football (aka Soccer)(字符串处理+sort排序)
- UVA 10194 Football (aka Soccer)
- UVa 10194 Football (aka Soccer) (模拟)
- UVA 10194 - Football (aka Soccer)
- UVA10194 Football (aka Soccer) 排序
- UVa 10194 - Football (aka Soccer)
- UVA10194 - Football (aka Soccer)
- uva 10194 Football (aka Soccer)
- uva 10194 Football (aka Soccer)
- UVA 10194 - Football (aka Soccer)
- UVA - 10194 Football (aka Soccer) 多种排序
- uva 10194 - Football (aka Soccer)
- UVA 10194 Football (aka Soccer) 足球成绩统计 检索+模拟
- UVA 10194 Football (aka Soccer)
- uva 10194 - Football (aka Soccer)
- UVA10194 - Football (aka Soccer)
- UVA - 10194 Football (aka Soccer)(sort函数用法)
- UVa 10194 - Football (aka Soccer)
- UVA 10194 Football (aka Soccer)
- UVA 10194 Football (aka Soccer)