Пример #1
0
int find_lcs(string& reference, string& query, int& refindex, int& queryindex, int& max_len, 
			automata_state automata[], int& sz, int& last, bool extend, ofstream& fp_detail)
{
	//If there exists a Suffix Automata then we do not create again
	if(extend == true)
		initialize_automata(STATE_SIZE, automata);

	//cout << "Reference = " << strref << endl;
	//cout << "Length = " << strref.length() << endl;

	//Assuming that there exists no Suffix Automata for a reference 
	//sequence and we have a Suffix Automata with an initial node t_o.
	//For each character of a reference sequence we extend that Automata
	//In the beginning the last node of Automata is the initial node,
	//hence for the first itertion last node is the 0th index of 
	//the automata array and size sz of the Automata is 1
	for(int i = 0; i < reference.length() && extend; i++)
	{
		extend_automata(reference.at(i), i, last, sz, automata);
	}

	//Find the Longest Common Substring between a reference and query
	//using Suffix Automata built on the reference sequence
	longest_common_substring(query, refindex, queryindex, max_len, automata, fp_detail);

	//fp_detail << endl << "Reference Index = " << refindex << endl;
	//fp_detail << "Query Index = " << queryindex << endl << endl;
	//fp_detail << "Substring = " << query.substr(queryindex, max_len) << endl;
	//fp_detail << "Longest Common Substrings: " << max_len << endl;
	
	return 0;
}
Пример #2
0
int main(void)
{
    char str1[1000],str2[1000];
    printf("请输入第一个字符串:");
    gets(str1);
    printf("请输入第二个字符串:");
    gets(str2);
    int len = longest_common_substring(str1, str2);
    printf("最长公共连续子串的长度为:%d\n",len);
    return 0;
}