gouzaogongoo

来源:百度文库 编辑:神马文学网 时间:2024/07/02 18:37:37
#include
#include
#define   MAX   99
//typedef   char   MM;
void   main()
{   int   i,j,m,n,h=0;
  char   x[MAX]={ '   ', '   '},y[MAX]={ '   ', '   '},b[MAX][MAX]={ '   '};
  int   c[MAX][MAX]={0};
  char   temp[MAX]={ '   '};
  cout < < "**本程序可以求得字符数在99以内的任意两个字符串的最大公共子序列**\n ";
  cout < < "请输入第一个字符串的长度m= ";
  cin> > m;
  cout < < "请输入第一个字符串(“回车”结束)\n如果输入的字符数超过m,则会出错!\nx[ " <       for(i=0;i <=m;i++)
{for(j=0;j <=n;j++)
    cout <             cout < }
cout < < "b[m][n]中的内容:\n ";
      for(i=1;i <=m;i++)
{for(j=1;j <=n;j++)
    cout <             cout < }
i=m,j=n;
while(1)
{if(i==0││j==0)   break;
if(b[i][j]== '\\ '){
temp[h++]=x[i];                                         //反序记录最长公共子序列到temp中
i=i-1,j=j-1;
}
else
if(b[i][j]== '│ ')        
i=i-1;
else
j=j-1;}
cout < < "\nx[ " < for(i=h-1;i> =0;i--)                                         //格式化输出最长公共子序列
          if(i==h-1)
  if(h==1)
  cout < < "LCS: < " < ";
  else
                          cout < < "LCS: < " <   else  
  if(i==0)
  cout < < ", " < ";
          else
                  cout < < ", " < cout < < "\n " < }