Moderator: Board moderators
removed after AC
At last Acc
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
aAaAAa
aaaaaa
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)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);
}
}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);
}Users browsing this forum: No registered users and 1 guest