uva 644 - Immediate Decodability

#include<iostream>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;

char codes[9][12];
int k = 1,num;

bool solve(){
    for(int i = 0; i < num; i++){
        for(int j = 0; j < num; j++){
            int flag = 1;
            if(j!=i && strlen(codes[j]) > strlen(codes[i])){
                for(int k = 0; k < strlen(codes[i]); k++)
                    if(codes[i][k] != codes[j][k])
                        flag = 0;
                if(flag)
                    return false;
            }
        }
    }
    return true;
}

int main(){
    num = 0;

    while(cin >> codes[num]){
        if(codes[num][0] == '9'){
            if(solve())
                cout << "Set " << k++ << " is immediately decodable" << endl;
            else
                cout << "Set " << k++ << " is not immediately decodable" << endl;
            num = 0;
        }else
            num++;
    }

    return 0;
}

 

posted @ 2015-07-16 19:51  杨永华  阅读(115)  评论(0编辑  收藏  举报