644--Immediate Decodability

#include<stdio.h> #include<string.h> #include<stdlib.h> #define LOCAL char codes[10][12]; int cmp_string(const void* _a,const void* _b) { char* a=(char* )_a; char* b=(char* )_b; return strcmp(a,b); } int deter(char* s1,char* s2) { int len1=strlen(s1); int len2=strlen(s2); int i,j; if(len1>=len2) return 0; else { for(i=0,j=0;i<len1;i++,j++) if(s1[i]!=s2[j]) return 0; return 1; } } int main() { #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int i=0,num=0,k,flag=1; while(scanf("%s",codes[i])!=EOF) { if(codes[i][0]!='9') i++; else { flag=1; num++; ////sort the string qsort(codes,i,sizeof(codes[0]),cmp_string); for(k=0;k<i-1;k++) if(deter(codes[k],codes[k+1])) { flag=0; break; } if(flag==0) printf("Set %d is not immediately decodable/n",num); else printf("Set %d is immediately decodable/n",num); i=0; } } return 0; }

你可能感兴趣的:(String)