UVA - 644 Immediate Decodability

来源:互联网 发布:知乎怎么提问 编辑:程序博客网 时间:2024/05/26 09:55

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19143

水题,问你给定的一组字符串中是否有字符串是另一个字符串的前缀,因为题目数据很小,直接枚举就好了,注意输入的时候就行。

#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int main(){    //freopen("a.txt","r",stdin);    char s[15][15];    int n,i,j,k=0,x,y=1,flag;    while(scanf("%s",s[k])!=EOF)    {        flag=0;        if(s[k][0]=='9')        {            //printf("%d\n",k);            for(i=0;i<k;i++)            {                for(j=i+1;j<k;j++)                {                    int l1=strlen(s[i]);                    int l2=strlen(s[j]);                    l1=min(l1,l2);                    for(x=0;x<l1;x++)                    {                        if(s[i][x]!=s[j][x]) break;                    }                   //printf("%d\n",x);                    if(x==l1) {flag=1;break;}                }                if(flag) break;            }            if(flag)            printf("Set %d is not immediately decodable\n",y++);            else printf("Set %d is immediately decodable\n",y++);            k=0;        }        else k++;    }return 0;}


0 0
原创粉丝点击