#include<fstream>
#include <ctype.h>
using namespace std;
const int Size=999999;
char c,subseq2[Size];
int count=0,LCStable[Size]={0};
/*----------------------------------------------------------
函數名稱:LCSsolver()
參數:x:subseq1的一個字
subseq2[]:第一個字串
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;
ifstream input2("input2.txt");
do
{
input2.get(c);
if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
subseq2[count++]=tolower(c);
}while(!input2.eof());
input2.close();
ifstream input1("input1.txt");
do
{
input1.get(c);
if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
osolution=LCSsolver(tolower(c) ,subseq2, count);
}while(!input1.eof());
input2.close();
ofstream output("output.txt");
output<<osolution<<endl;
output.close();
}
-------------------------------------------------------------------------------------------------------------------------------------------
其實ver3沒改什麼東西,只是用了我比較喜歡的fstream的方式來寫檔案的輸出入XD
這樣看起來比ver2還要如容易看,而且標頭檔也少了很多
哀哀哀 我真不怎麼喜歡去處理資料
感覺起來真的挺麻煩的~哈