POJ 1458 Common Subsequence

 1 /**************************************
 2Problem: POJ 1458 Common Subsequence
 3Time: 0MS
 4Memory: 376K
 5Accepted Time: 2009-04-11 13:15:12
 6Tips:《程序设计导引及在线实践》10.5
 7**************************************/

 8 #include  < stdio.h >
 9 #include  < string .h >
10 int  main()
11 {
12    char a[210],b[210];
13    while(scanf("%s%s",a+1,b+1)!=EOF)
14    {
15        int table[210][210],i,j;
16        int lena=strlen(a+1);
17        int lenb=strlen(b+1);
18        for(i=0;i<=lena;i++)table[i][0]=0;
19        for(i=0;i<=lenb;i++)table[0][i]=0;
20        for(i=1;i<=lena;i++)
21        {
22            for(j=1;j<=lenb;j++)
23            {
24                if(a[i]==b[j])table[i][j]=table[i-1][j-1]+1;
25                else if(table[i-1][j]>table[i][j-1])table[i][j]=table[i-1][j];
26                else table[i][j]=table[i][j-1];
27            }

28        }

29        printf("%d\n",table[lena][lenb]);
30    }

31    return 0;
32}

33

你可能感兴趣的:(sequence)