UVA 644 Immediate Decodability

判断前缀是否和某个字符串相同,不多说了直接上代码,uva的字符模拟终于要结束了啊啊,acm之路还很长希望自己和大家能坚持下去。
[cpp] view plaincopy
#include<stdio.h> 
#include<string.h> 
 
char isprefix(const char s[][12],int n)//判断前缀 

      for(int i=0;i<n;i++) 
      for(int j=i+1;j<n;j++) 
      { 
          char ch1[12]={'\0'},ch2[12]={'\0'}; 
          int len=strlen(s[i])<strlen(s[j])?strlen(s[i]):strlen(s[j]); 
          memcpy(ch1,s[i],len);memcpy(ch2,s[j],len);//构造前缀 
          if(!strcmp(ch1,ch2))return 0;//存在前缀序列 
      }  饮品店加盟www.qidouzl.com
      return 1; 

 
char str[15][12]; 
 
int main(){ 
    freopen("input.txt","r",stdin); 
    int n=0,count=1; 
    while(gets(str[n])!=NULL) 
    { 
        if(strcmp(str[n],"9")==0){ 
 
            if(isprefix(str,n+1)) 
                printf("Set %d is immediately decodable\n",count); 
            else 
                printf("Set %d is not immediately decodable\n",count); 
            count++;n=0; 
        } 
        else  n++; 
    } 
    return 0; 

posted @ 2014-02-20 10:03  刘俊鹏123  阅读(252)  评论(0编辑  收藏  举报
重生之大文豪