Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
超级郁闷中!哪位大牛来帮俺看下啊!答案输出是正确的但是一直是runtime error!(副代码)#include<stdio.h> #include<string.h> #include <stdlib.h> struct tel { int p; char a[100]; }num[100]; int cmp ( const void *m , const void *n) { return strcmp( (*(tel *)m).a , (*(tel *)n).a); } void delete1 (char a[100]) { int i,j,q; for(i=0;a[i]!='\0';i++) { if(a[i]=='-') { for(j=i;a[j+1]!='\0';j++) a[j]=a[j+1]; a[j]='\0'; } } } int main() { int i,j,m,len,count=0; while(scanf("%d",&m)!=EOF) { for(i=0;i<m;i++) { num[i].p=1; scanf("%s",num[i].a); delete1(num[i].a); for(j=0;num[i].a[j]!='\0';j++) { if(num[i].a[j]=='A'||num[i].a[j]=='B'||num[i].a[j]=='C') num[i].a[j]='2'; if(num[i].a[j]=='D'||num[i].a[j]=='E'||num[i].a[j]=='F') num[i].a[j]='3'; if(num[i].a[j]=='G'||num[i].a[j]=='H'||num[i].a[j]=='I') num[i].a[j]='4'; if(num[i].a[j]=='J'||num[i].a[j]=='K'||num[i].a[j]=='L') num[i].a[j]='5'; if(num[i].a[j]=='M'||num[i].a[j]=='N'||num[i].a[j]=='O') num[i].a[j]='6'; if(num[i].a[j]=='P'||num[i].a[j]=='R'||num[i].a[j]=='S') num[i].a[j]='7'; if(num[i].a[j]=='T'||num[i].a[j]=='U'||num[i].a[j]=='V') num[i].a[j]='8'; if(num[i].a[j]=='W'||num[i].a[j]=='X'||num[i].a[j]=='Y') num[i].a[j]='9'; } } for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) { if(num[i].p!=-1) { if(strcmp(num[i].a,num[j].a)==0) { num[i].p++; num[j].p=-1; count++; } } } qsort(num,m,sizeof(num[0]),cmp); if(count==0) printf("No duplicates."); else for(i=0;i<m;i++) { if(num[i].p>=2) { len=strlen(num[i].a); for(j=0;j<3;j++) printf("%c",num[i].a[j]); printf("-"); for(j=3;j<len;j++) printf("%c",num[i].a[j]); printf(" %d",num[i].p); printf("\n"); } } } while(1); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator