644 - Immediate Decodability
Moderator: Board moderators
644 - Immediate Decodability
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]
Last edited by deddy one on Tue Apr 29, 2003 11:47 am, edited 1 time in total.
-
- New poster
- Posts: 1
- Joined: Tue Apr 22, 2003 2:14 pm
- Contact:
644
Help me please. I don't know what is wrong. I HATE THIS JUDGE!!!
Maybe u got some source.
[pascal]
program decoding;
var
a:array[1..9] of string[10];
i,j,k,l:byte;
b:string[10];
res:boolean;
function equ(a1,a2:string):boolean;
var i:byte;
res:boolean;
begin
res:=true;
for i:=1 to length(a2) do
res:=res and (a1=a2);
equ:=res;
end;
procedure mainloop;
var w1,w2:byte;
begin
while (k<i) and not(res) do
begin
inc(k);
j:=1;
while (j<=i) and not(res) do
begin
w1:=length(a[k]);
w2:=length(a[j]);
if (j<>k) and (w1<=w2) then
res:=res or equ(a[j],a[k]);
inc(j);
end;
end;
end;
begin
i:=0; l:=0;
while not eof(input) do
begin
readln(input,b);
if b='9' then
begin
k:=0; inc(l);
res:=false;
mainloop;
str(l,b);
if not(res) then
writeln(output,'Set '+b+' is immediately decodable')
else
writeln(output,'Set '+b+' is not immediately decodable');
i:=0;
end
else
begin
inc(i);
a:=b;
end;
end;
end.[/pascal]

Maybe u got some source.
[pascal]
program decoding;
var
a:array[1..9] of string[10];
i,j,k,l:byte;
b:string[10];
res:boolean;
function equ(a1,a2:string):boolean;
var i:byte;
res:boolean;
begin
res:=true;
for i:=1 to length(a2) do
res:=res and (a1=a2);
equ:=res;
end;
procedure mainloop;
var w1,w2:byte;
begin
while (k<i) and not(res) do
begin
inc(k);
j:=1;
while (j<=i) and not(res) do
begin
w1:=length(a[k]);
w2:=length(a[j]);
if (j<>k) and (w1<=w2) then
res:=res or equ(a[j],a[k]);
inc(j);
end;
end;
end;
begin
i:=0; l:=0;
while not eof(input) do
begin
readln(input,b);
if b='9' then
begin
k:=0; inc(l);
res:=false;
mainloop;
str(l,b);
if not(res) then
writeln(output,'Set '+b+' is immediately decodable')
else
writeln(output,'Set '+b+' is not immediately decodable');
i:=0;
end
else
begin
inc(i);
a:=b;
end;
end;
end.[/pascal]
-
- Experienced poster
- Posts: 192
- Joined: Sat Nov 30, 2002 5:14 am
644 - WA
Hi,
could someone please give me some test inputs and outputs for problem 644? I've tried lots of tests and my algorithm seems correct but judge gave me WA. Are the constraints of the problem correct? (2-8 codes in each set with 1-10 bits) Thanks in advance!
Jeno
could someone please give me some test inputs and outputs for problem 644? I've tried lots of tests and my algorithm seems correct but judge gave me WA. Are the constraints of the problem correct? (2-8 codes in each set with 1-10 bits) Thanks in advance!
Jeno
Just check the following test case...
Input:
Output:
Hope it works.
Input:
Code: Select all
01
10
0010
001
9
Code: Select all
Set 1 is not immediately decodable
Ami ekhono shopno dekhi...
HomePage
HomePage
644 - Immediate Decodability ..Getting WA
need help...!!!
anyone pls help me!!
thanks...
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;
}
thanks...
-
- New poster
- Posts: 9
- Joined: Wed Jul 09, 2008 10:12 pm
644 - Immediate Decodability : TERMINATION CONDITION
What is the termination condition of this problem?
No, such type of terination condition.I am getting TLE because of this.Pls, inform
No, such type of terination condition.I am getting TLE because of this.Pls, inform

-
- Learning poster
- Posts: 97
- Joined: Fri Aug 22, 2008 10:18 pm
- Location: CSE.SUST.SYLHET
Re: 644 - Immediate Decodability : TERMINATION CONDITION
Hello tanvir_cse
U have to read the input upto end of file.
and when u get 9 u will print result
take input like that
U have to read the input upto end of file.
and when u get 9 u will print result
take input like that
while(scanf(" %s", code[num]) == 1)
{
while(1)
{
if (code[num][0] == '9') break;
scanf(" %s", code[++num]);
}
//some code here;
}
-
- New poster
- Posts: 5
- Joined: Wed Sep 23, 2009 8:57 am
Re: 644 - Immediate Decodability
getting WA.can anyone please help?
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;
}
Re: 644 - Immediate Decodability
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