close

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


int LCSsolver(char x,vector<char> subseq,int lenth)
{
int solution=0,temp1=0,temp2=0;

for(int i=1;i<lenth;i++)
{
if(x!=subseq[i])
{
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-1.txt");
do
{
input2.get(c);
if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
subseq2.push_back(tolower(c));
}while(!input2.eof());
input2.close();

ifstream input1("input1-1.txt");
do
{
input1.get(c);
if((c>=48 && c<=57)||(c>=65 && c<=90)||(c>=97 && c<=122))
osolution=LCSsolver(tolower(c) ,subseq2, subseq2.size());
}while(!input1.eof());
input2.close();

ofstream output("output.txt");
output<<osolution<<endl;
output.close();
}

--------------------------------------------------

聽別人說用vector寫可以省空間

但是速度慢了約八十倍吧= =

從六秒變成八分鐘....

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

    野小孩的部落格

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