This question can be seen that someone uses the longest public subsequence to do it. In fact, it is completely useless. Just traverse it once and it is a water question.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Define N 1005
Int main ()
{
Char s1 [N], s2 [N];
Int mark [27] [27];
Int I, j;
Int flag;
Int T;
Char x, y;
Scanf ("% d", & T );
Int count = 1;
While (T --)
{
Getchar ();
Gets (s1 );
Gets (s2 );
Int n;
Scanf ("% d", & n );
Memset (mark, 0, sizeof (mark ));
While (n --)
{
Getchar ();
Scanf ("% c", & x, & y );
Mark [x-'A' + 1] [y-'A' + 1] = 1;
}
Int ln1, ln2;
Ln1 = strlen (s1 );
Ln2 = strlen (s2 );
I = 0;
J = 0;
Flag = 0;
For (I = 0; I <ln1; I ++)
{
If (j = ln2)
Break;
If (s1 [I] = s2 [j])
{
J ++;
Continue;
}
While (s2 [j]! = S1 [I])
{
If (j = ln2)
{
Flag = 1;
Break;
}
If (mark [s2 [j]-'A' + 1] [s1 [I]-'A' + 1] = 1)
{
J ++;
Break;
}
Else
J ++;
}
}
If (! Flag)
Printf ("Case # % d: happy \ n", count ++ );
Else
Printf ("Case # % d: unhappy \ n", count ++ );
}
Return 0;
}