Saturday 11 April 2009

POJ 1056





#include <iostream>
#include <string.h>
using namespace std;
bool sub(char const* a,char const* b){
for(;*a==*b&&*a&&*b;++a,++b);
return *a==0||*b==0;
}
bool ok(char vs[1024][11],int n){
for(int i=0;i<n-1;++i)
for(int j=i+1;j<n;++j)
if(sub(vs[i],vs[j]))
return false;
return true;
}
int main(){
int N=0;
for(char buf[1024][11];;){
int n=0;
for(;cin>>buf[n]&&0[buf[n++]]!='9';);
if(cin.eof())break;
--n;
cout<<"Set "<<++N<<(ok(buf,n)?" is":" is not")<<" immediately decodable"<<endl;
}
return 0;
}

No comments:

Post a Comment