close

 

#include<fstream>
#include <ctype.h> 
#include <cstdio>
#include <cstdlib>
using namespace std;
const int Size=999999;
char c,subseq2[Size];
int count=0,LCStable[Size]={0};

/*----------------------------------------------------------
函數名稱:LCSsolver()
參數:x:subseq2的一個字
subseq1[]:第一個字串
lenth:字串長度
用途:計處出最長子序列的長度
----------------------------------------------------------*/
int LCSsolver(char x,char subseq1[],int lenth)
{
int solution=0,temp1=0,temp2=0;

for(int i=1;i<lenth;i++)
{
if(x!=subseq1[i-1])
{
temp1=LCStable[i];
solution=LCStable[i]=LCStable[i-1]>=LCStable[i]?LCStable[i-1]:LCStable[i];
}
else
{
temp2=LCStable[i];
solution=LCStable[i]=temp1+1;
temp1=temp2;
}
}
return solution;
}


void main()
{  
   int osolution=0;


freopen("input2.txt","r",stdin);
    do 
{
       c=getchar();
       if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
  subseq2[count++]=tolower(c);
    }while (c!=EOF);
    fclose(stdin);


freopen("input1.txt","r",stdin);
    do 
{
       c=getchar();
       if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
  osolution=LCSsolver( tolower(c),subseq2,count );
    }while (c!=EOF);
    fclose(stdin);
        
freopen("output.txt","w",stdout);
printf("%d\n", osolution);
fclose(stdout);
system("pause");
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 野小孩 的頭像
    野小孩

    野小孩的部落格

    野小孩 發表在 痞客邦 留言(0) 人氣()