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 35060616 at 2007-08-28 18:59:50
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int min_operation(char *s1, char *s2)
{
    int n1 = strlen(s1),n2 = strlen(s2);
    int i,j;
    int flag1 ,flag2;
    int max = 0;
    //int a[][]
    int a[100][100] = {0};
    flag1=n1;
    flag2=n2;
    for(i=1;i<=n1;i++) 
                      for(j=1;j<=n2;j++)
                      {
                                        if(s1[i-1] == s2[j-1])
                                        {
                                                    a[i][j] = a[i-1][j-1] + 1;
                                                    if(max<=a[i][j])
                                                  {
                                                     flag1=i;
                                                     flag2=j;
                                                     max=a[i][j];
                                                  }
                                        }
                                        else
                                            a[i][j]=(a[i-1][j]>a[i][j-1])?a[i-1][j]:a[i][j-1];
                      }
    //printf("%d %d %d",a[n1][n2],flag1,flag2);
    return ((n1>n2)?n1:n2) - a[n1][n2] + ((n1-flag1>n2-flag2)?n1-flag1:n2-flag2);
}
main()
{
      int t;
      int n,m;
      int i=0;
      char *s1, *s2;
      
      scanf("%d",&n);
      s1=(char * )malloc(n);
      scanf("%s",s1);
      
      scanf("%d",&m);
      s2=(char * )malloc(m);
      scanf("%s",s2);
      printf("%d\n",min_operation(s1,s2));
                
      free(s1);
      free(s2);
          
      
}
      
      
      

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