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 Subsequence

Posted by whus200532550008 at 2006-12-23 16:07:16
#include <iostream.h> 
#include <string.h> 
#define MAX 1000 
char str1[MAX],str2[MAX]; 
int com[MAX][MAX], i, j; 
void main(){ 
 while(cin >> str1 >> str2){ 
  int len1=strlen(str1); 
  int len2=strlen(str2); 
        for(i=0;i<MAX;i++) for(j=0;j<MAX;j++) com[i][j]=0; 
  for(i=1;i<=len1;i++) for(j=1;j<=len2;j++){ 
   if(str1[i-1]==str2[j-1]) com[i][j] = 1+ com[i-1][j-1];
   else{
    if(com[i-1][j]>com[i][j-1]) com[i][j]=com[i-1][j]; 
    else com[i][j]=com[i][j-1]; 
   } //else
  } //for
  cout << com[len1][len2] <<endl; 
 } //while
} //main

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