UVA-644 Immediate Decodability

UVA-537 Artificial Intelligence?

题目大意:如果输入的单词中,有的单词是其它单词的前缀,则 is not immediately decodable ,反之则是 is immediately decodable

Sample Input

01
10
0010
0000
9
01
10
010
0000
9

Sample Output

Set 1 is immediately decodable
Set 2 is not immediately decodable

解题思路:逐个比较即可

//UVA-644 Immediate Decodability
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;

char m[10005][10005];
char n[10005];
int count = 1;

int main() {
    while (scanf ("%s",n) != EOF) {
        int t = 0;
        while(strcmp(n,"9\0") != 0) {
            strcpy(m[t++], n);
            scanf("%s",n);
        }
        int flag = 1;
        for (int i = 0; i < t; i++)
            for (int j = i + 1; j < t; j++) {
                int len1 = strlen (m[i]);
                int len2 = strlen (m[j]);
                int k;
                for (k = 0; k < min (len1,len2); k++) {
                    if (m[i][k] != m[j][k])
                        break;
                    if (k == min(len1,len2) - 1) {
                        flag = 0;
                    }
                }
            }
        if (flag)
            printf ("Set %d is immediately decodable\n",count++);
        else
            printf ("Set %d is not immediately decodable\n",count++);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值