644 - Immediate Decodability
Posted: Sat Jan 18, 2003 1:33 pm
I'm getting WA in this problem
what's wrong
is it my function checking?????
[c]
cut
[/c]
what's wrong
is it my function checking?????
[c]
cut
[/c]
Code: Select all
01
10
0010
001
9
Code: Select all
Set 1 is not immediately decodable
Code: Select all
#define foriz(i,n) for( i = 0 ; i < n ; i ++ )
bool immediately_decodable ( vecs cd )
{
sort( cd.begin() , cd.end() );
int i , j;
foriz ( i , sz(cd) )
{
foriz ( j , sz(cd) )
{
if ( i != j && sz(cd[j]) >= sz(cd[i]) )
{
string x = cd[j].substr ( 0 , sz(cd[i]) );
if ( x == cd[i] )
return false;
}
}
}
return true;
}
int main ()
{
int cas = 1;
string s;
while ( !feof(stdin) )
{
vecs codes;
while ( true )
{
cin >> s;
if ( s == "9" ) break;
else codes.pb (s);
}
if ( immediately_decodable ( codes ) )
printf ( "Set %d is immediately decodable\n" , cas ++ );
else
printf ( "Set %d is not immediately decodable\n" , cas ++ );
codes.clear();
}
return 0;
}
while(scanf(" %s", code[num]) == 1)
{
while(1)
{
if (code[num][0] == '9') break;
scanf(" %s", code[++num]);
}
//some code here;
}
Code: Select all
#include<stdio.h>
#include<string.h>
int main(){
int a,b=0,d,e,f,x,y,z,bi[9][10],l,len[10],zz=1,aa,p,q;
char c,m[11];
while(gets(m)){
l=strlen(m);
len[b]=l;
for(a=0;a<l;a++)
bi[b][a]=m[a]-48;
b++;
if(m[0]!='9')
continue;
p=0;q=0;
for(e=0;e<b;e++){
for(f=e+1;f<b;f++){
if(len[e]<len[f]){
for(a=0;a<len[e];a++){
if(bi[e][a]!=bi[f][a])
break;
}
}
if(a==len[e]){
p++;
break;
}
}
if(a==len[e])
break;
}
for(e=b-1;e>=0;e--){
for(f=e-1;f>=0;f--){
if(len[e]<len[f]){
for(aa=0;aa<len[e];aa++){
if(bi[e][aa]!=bi[f][aa])
break;
}
}
if(aa==len[e]){
q++;
break;
}
}
if(aa==len[e])
break;
}
if((p>0)||(q>0)){
p=0;q=0;
printf("Set %d is not immediately decodable\n",zz);
zz++;
b=0;
continue;
}
if((p==0)&&(q==0)){
printf("Set %d is immediately decodable\n",zz);
zz++;
b=0;
}
}
return 0;
}
Try the following input:fahim_xubayer wrote:getting WA.can anyone please help?
Code: Select all
01
01
9
Code: Select all
Set 1 is not immediately decodable
Thanks for sharing this great test case!Jan wrote:Just check the following test case...