## 2254 - Is judge work correct with this problem?

Do you want to discuss about these problems? Go now!
Users are shared (no need to re-register).

Moderator: Board moderators

Master
Learning poster
Posts: 82
Joined: Thu Oct 10, 2002 1:15 pm
Location: St. Johns, Canada
Contact:

### 2254 - Is judge work correct with this problem?

i have tryed this problem several time and getting WA. But i have solved all the LCS problem of this site. I do not find any error or bug with this problem. Here is my code:

[cpp]
#include<stdio.h>
#include<string.h>

#define MAX 100

char str1[MAX],str2[MAX];
int sp;

void p_lcs(int b[MAX][MAX],int i,int j)
{
if ( (i == 0) || ( j == 0) )
return ;
if( b[j] == 1 )
{
p_lcs(b,i-1,j-1);
str1[sp++] = str1[i-1];

}
else if( b[j] == 2)
p_lcs(b,i-1,j);
else
p_lcs(b,i,j-1);
}

int test(void)
{
int c[MAX][MAX]={0},b[MAX][MAX]={0},l1,l2;
l1 = strlen(str1)+1;
l2 = strlen(str2)+1;

register int i,j;
for(i=1;i<l1;i++)
{
for(j=1;j<l2;j++)
{
if( str1[i-1] == str2[j-1] )
{
c[j] = c[i-1][j-1] + 1;
b[j] = 1;
}
else if(c[i-1][j] >= c[j-1])
{
c[j] = c[i-1][j];
b[j] = 2;
}
else
c[j] = c[j-1];
}
}
sp = 0;

if(c[l1-1][l2-1])
{
p_lcs(b,l1-1,l2-1);
str1[sp]='\0';
}

return c[l1-1][l2-1];
}

main(void)
{
int n,l,i;
char ms[MAX];

// freopen("c:\\in\\2254.in","r",stdin);
gets(ms) ;
sscanf(ms,"%d",&n);
while(n)
{

l = 1;
gets(str1);
for(i=1;i<n;i++)
{
gets(str2);
if(l)
l = test();

}
printf("%d\n",l);

gets(ms);
sscanf(ms,"%d",&n);
}
return 0;
}[/cpp]

Can any one prove that my code gives wrong answer?
Or-
Do the judge wrong?

M H Rasel
CUET Old Sailor