uva 644 - Immediate Decodability

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=585

可以学习哈弗曼编码,以及二叉树编码,就知道怎么是immediately code

#include<iostream>
#include<string>
using namespace std;
int main(){
    string code[5000],l;
    int num=0,temp=0,numNine=0;
    while(getline(cin,l)){
        if(l[0]=='9'){
            numNine++;
            for(int i=0;i<num;i++){
                for(int j=0;j<num;j++){
                    if(j==i)
                        continue;
                    if(code[j].find(code[i],0)==0){
                        temp=1;
                        break;
                    }
                }
                if(temp)
                    break;
            }
            if(!temp)
                cout<<"Set "<<numNine<<" is immediately decodable"<<endl;
            else
                cout<<"Set "<<numNine<<" is not immediately decodable"<<endl;
            num=0;
            temp=0;
            code->clear();
            continue;
        }
        code[num++]=l;
    }
}

 

 

posted on 2013-12-16 13:54  云在心  阅读(156)  评论(0)    收藏  举报

导航