为什么一直是Wrong Answer?哪里的代码有问题?
1007. Common Subsequence总提交数量: 522 通过数量: 90
时间限制:1秒 内存限制:256兆
题目描述
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm>, another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence(严格递增) <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
输入格式
The first line is a positive integer N (1 <= N <= 10000), giving the number of the test cases.
Each test case contains two strings representing the given sequences. The sequences are separated by any number of white spaces. Both the length of the sequences are less than 15.
输出格式
For each test case, the program prints the length of the maximum-length common subsequence from the beginning of a separate line.
样例输入
将样例输入复制到剪贴板
3
abcfbc abfcab
programming come
abcd mnp
样例输出
4
2
0
我的做法是:
#include <string.h>
int main()
{
int n,i,j,k,counter;
char b[15], a[15];
scanf("%d",&n);
for(i=0;i<n;i++)
{
k=0;
counter = 0;
scanf("%s",b);
scanf("%s",a);
for(j=0;j<strlen(a);j++)
{
for(k;k<strlen(b);k++)
{
if(a[j] == b[k])
{
counter++;
break;
}
}
}
printf("%d\n",counter);
}
return 0;
}