Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

common

Posted by 420321460619891005 at 2010-06-30 10:06:01
#include <stdio.h>
#include <string.h>

#define MAX 1000

char zly1[MAX],zly2[MAX];
int zlyMaxLen[MAX][MAX];

void main()
{
    while(scanf("%s%s",zly1+1,zly2+1)!=EOF)
    {
        int L1,L2;
        L1=strlen(zly1+1);
        L2=strlen(zly2+1);
    
        int i,j;
        for(i=0;i<L1;i++)
		{
			zlyMaxLen[i][0]=0;
		}
        for(j=0;j<L1;j++)
		{
			zlyMaxLen[0][j]=0;
		}
        for(i=1;i<=L1;i++)
		{
            for(j=1;j<=L2;j++)
			{
                if(zly1[i]==zly2[j])
                    zlyMaxLen[i][j]=1+zlyMaxLen[i-1][j-1];
                else 
					zlyMaxLen[i][j]=zlyMaxLen[i-1][j]>zlyMaxLen[i][j-1]?zlyMaxLen[i-1][j]:zlyMaxLen[i][j-1];
			}
		}

        printf("%d\n",zlyMaxLen[L1][L2]);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator