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> int changestring(char str[],int length) { int i,j; for(i=0;i<length;i++) { //如果连续输入2个‘-’则出现错误 if(str[i]=='-') { j=i; do { str[j]=str[j+1]; j++; }while(str[j]); } if(str[i]>='A'&&str[i]<='C') str[i]='2'; if(str[i]>='D'&&str[i]<='F') str[i]='3'; if(str[i]>='G'&&str[i]<='I') str[i]='4'; if(str[i]>='J'&&str[i]<='L') str[i]='5'; if(str[i]>='M'&&str[i]<='O') str[i]='6'; if(str[i]>='P'&&str[i]<='S') str[i]='7'; if(str[i]>='T'&&str[i]<='V') str[i]='8'; if(str[i]>='W'&&str[i]<='Y') str[i]='9'; } return 1; } int main() { int n,i,j,k,length,count[101],flag=0; char str[100][22],rank[]="0123456789"; freopen("bb.txt","r",stdin); while(scanf("%d",&n)!=EOF && n!=0) { //输入部分 getchar(); for(i=0;i<n;i++) { scanf("%s",&str[i]); length=strlen(str[i]); changestring(str[i],length); } for(i=0;i<n;i++) { count[i]=1; for(j=i+1;j<n;j++) { if(!strcmp(str[i],str[j])) { count[i]++; for(k=j;k<n-1;k++) strcpy(str[k],str[k+1]); n--; j--; } } } for(i=0;i<n;i++) { if(count[i]!=1) flag=1; } if(flag==0) printf("No duplicates. \n"); /* for(i=0;i<10;i++) for(j=0;j<n;j++) if(count[j]>1 && rank[i]==str[j][0]) printf("%c%c%c%c%c%c%c%c %d\n",str[j][0],str[j][1],str[j][2],'-',str[j][3],str[j][4],str[j][5],str[j][6],count[j]); */ for(i=0;i<10;i++) for(j=0;j<n;j++) if(count[j]>1 && rank[i]==str[j][0]) { for(k=0;k<3;k++) printf("%c",str[j][k]); printf("-"); for(k=3;k<strlen(str[j]);k++) printf("%c",str[j][k]); printf(" %d\n",count[j]); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator