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

help!!!!! 真的假的这代码过不去吗???????????????????

Posted by sun_huangjian at 2007-08-28 14:52:32 on Problem 3356
#include   <stdio.h>   
  #include   <string.h>   
  #define   N   100
  int lcs_len(char *a,char *b,   int c[][N])     
  {       
	  int m=strlen(a),n=strlen(b),i,j;     
	  for(i=0;i<=m;i++)       
		 c[i][0]=0;
	  for(j=0;j<=n;j++)       
		  c[0][j]=0;     
	  for(i=1;i<=m;i++)           
		  for(j=1;j<=n;j++)     
		  {   
			  if (a[i-1]==b[j-1])     
				c[i][j]=c[i-1][j-1]+1;       
			  else if(c[i-1][j]>=c[i][j-1])     
				  c[i][j]=c[i-1][j];   
				  else   
				  c[i][j]=c[i][j-1];   
	  }   
  return c[m][n];   
  }     
  int build_lcs(char *s,char *a,char *b)     
  {       
	  int k,i=strlen(a),j=strlen(b),c[N][N];     
	  k=lcs_len(a,b,c);     
	  s[k]='\0';     
	  while(k>0)     
		  if(c[i][j]==c[i-1][j])     
			  i--;     
			else  if(c[i][j]==c[i][j-1])     
				j--;     
		 else     
		  {   
			  s[--k]=a[i-1];   
			  i--;   
			  j--;
		 }     
	  return strlen(s);   
  }    
  void main()     
  {  
	  int i,n;
	 char a[N],b[N],str[N];
	 scanf("%d",&n);
	scanf("%s",a); 
	scanf("%d",&n);
	scanf("%s",b);

	 printf("%d\n",strlen(b)-build_lcs(str,a,b));  
  }     
  

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