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 |
Why Runtime Error初学者,就很暴力的写了C ,老是Runtime Error #include<stdio.h> #include<string.h> int judge(int ,char [100][100]); void main() { char input[100][100],temp[100]; int result[100]; int n,i=0; memset(input,'\0',sizeof(input)); do { n=0; memset(input,'\0',sizeof (input)); memset(temp,'\0',sizeof (temp)); scanf("%s",temp); if (temp==EOF) break; while(strcmp(temp,"9")) { strcpy(input[n],temp); n++; scanf("%s",temp); } result[i]=judge(n,input); if (result[i]==0) printf("Set %d is immediately decodable\n",i+1); else if (result[i]==1) printf("Set %d is not immediately decodable\n",i+1); i++; } while (1); } int judge (int n ,char input[100][100]) { int i,j,flag=0; char temp[100]; //需要<n,n为输入的个数 for (i=0;i<n;i++) for (j=i;j<n;j++) if (strlen(input[j])<strlen(input[i])) {strcpy(temp, input[i]);strcpy( input[i], input[j]);strcpy( input[j],temp);} //进行判断了 for (i=0;i<n;i++) { for (j=i+1;j<n;j++) { memset(temp,'\0',sizeof(temp)); strncpy(temp,input[j],strlen(input[i])); if (strcmp(input[i],temp)==0) { flag=1; break; } } if (flag==1) break; } return (flag); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator