Page 8 of 11

Posted: Sat Oct 20, 2007 10:27 pm
by Jan
Nope. If the solution is 'ab' then of course 'ba' is a solution, too. right?

Posted: Wed Mar 19, 2008 10:04 pm
by jackpigman
I've got all the test cases I could find right but still get's Wa....
Here's my code.

Code: Select all

removed after AC
Thanks for your help :D

Posted: Thu Mar 20, 2008 12:22 am
by Jan
There can be multiple cases. Your code works for only one case.

Posted: Thu Mar 20, 2008 6:21 pm
by jackpigman
I changed my code, but got a RTE :cry: :cry: :cry:
Please help me.......

Code: Select all

removed after AC

Posted: Thu Mar 20, 2008 7:19 pm
by emotional blind
when length of a = 1000, and strlen(a) = 1000 then you can't access a[strlen(a)] ie a[1000], coz your size of array is 1000 so that you can access 0 to 999. try increasing size by 1 ie set the max size to 1001.

Posted: Thu Mar 20, 2008 9:50 pm
by jackpigman
Thanks a lot emotional blind!!
finally got an AC :D :D :D :D

Re: 10252 - Common Permutation

Posted: Mon Jun 16, 2008 9:09 pm
by palash
pls help WA. I didn't find my bug in my code.every time i got WA here is my code

Code: Select all

At last Acc

Re: 10252 - Common Permutation

Posted: Mon Jun 30, 2008 12:07 pm
by maruf
Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of
what is meant hear by "permutation" && "subsequence"??
i am totally in dark :cry:
please help :oops:

Re: 10252 - Common Permutation

Posted: Mon Jun 30, 2008 4:46 pm
by Jan
Subsequence: Suppose you are given two strings A and B. B will be said the subsequence of A, if you can make B from A by deleting some (or none) characters.
Permutation: Suppose you are given two strings A and B. B will be said the permutation of A, if you can make B from A by re-arranging some (or none) characters.

So, 'abc' is a subsequence of 'adbfc' and 'aabc' is a permutation of 'caba'.

Re: 10252 - Common Permutation

Posted: Wed Jul 16, 2008 1:33 pm
by Galileo
Can someone tell me what is the output for?
aAaAAa
aaaaaa

WA Plz help

Posted: Thu Jul 17, 2008 8:23 am
by Galileo
nothing

Re: 10252 - Common Permutation

Posted: Wed Dec 31, 2008 5:01 am
by ExUCI
Hi, I just got AC without caring about such cases with uppercases like aaAAAaaa or whatever and there is no such thing. And yes, LCD can be used, I used it but I gonna change it for the simpler alg now!!

I read too many posters for nothing :evil:

Re: 10252 - Common Permutation

Posted: Mon Mar 30, 2009 3:06 am
by wsb7metal
I got AC!
I read just letters a..z and <space>
And ignore the last output, I dont know why, but work. =/

Re: 10252 - Common Permutation

Posted: Thu Jun 25, 2009 5:43 am
by banglacity
After suffering a lot, finally i got Ac :D

The only problem is- take input by gets() rather than scanf()

Hope it will work !

Re: 10252 - Common Permutation

Posted: Wed May 12, 2010 1:33 am
by amishera
My problem is rather simple. I used the print_LCS from the cormen book:

Code: Select all

PRINT-LCS(b, X, i, j )
1 if i = 0 or j = 0
2 then return
3 if b[i, j ] = “&”
4 then PRINT-LCS(b, X, i ? 1, j ? 1)
5 print xi
6 elseif b[i, j ] = “?”
7 then PRINT-LCS(b, X, i ? 1, j )
8 else PRINT-LCS(b, X, i, j ? 1)
and implemented in 2 ways:

recursive:

Code: Select all

void print(char a[], int i, int j)
{
	if (i == 0 || j == 0)
	{
		return;
	}
	if (op[i][j] == 3)
	{
		print(a, i-1,j-1);
		printf("%c", a[i-1]);
	}
	else if (op[i][j] == 1)
	{
		print(a, i-1,j);
	}
	else
	{
		print(a, i,j-1);
	}
}
and iterative:

Code: Select all

void print(char a[], int i, int j, int len)
{
	char pr[MAX];
	int k = len-1;

	while ((i != 0) && (j != 0))
	{		
		if (op[i][j] == 3)
		{
			i--,j--;
			pr[k] = a[i];
			k--;
		}
		else if (op[i][j] == 1)
		{	
			i--;
		}
		else
		{
			j--;
		}
	}
	
	pr[len] = '\0';
	printf("%s", pr);
}
The recursive is giving AC, but iterative is giving WA. While calling I pass the same parameters and for len pass the maximum length. The test cases passes for both implementations. Isn't this peculiar that it still gives WA for iterative one?