Find longest words int txt

Hello I have those 2 txt files:
Two things are infinite: the universe and human stupidity; and I'm not sure about the universe - Albert Einstein

Only two things are infinite in this world: the universe and stupidity of human; and I'm not sure about the universe - Something Copy

An I need to find the longest words if they are in both txt files. How I need to do that?
I've only do
int zpr = 0, zpb = 0, i = 0;
	while ((zpr = eil.find_first_not_of(skyrikliai, zpb)) != string::npos){
		zpb = eil.find_first_of(skyrikliai, zpr);
		zodziai[i] = eil.substr(zpr, zpb - zpr);
	n = i - 1;

Last edited on
Just to clarify, are you trying to find the longest common substring between the two strings? Or, are you trying to find the longest common word shared between the two strings (a word in this case defined as a series of alphanumeric characters separated by whitespace and punctuation). Is the comparison case-sensitive?
Last edited on
I'm trying to find longest words shared between two strings.
Last edited on
Any ideas?
Load the two files into two deque<string> objects. Sort them by length of string (longest first). Find the first two matching strings. You may want to use a case-insensitive comparator.

If file size is an issue, use a single map<string,unsigned> to store the strings and the number of files it was found in. The map comparitor should sort by (1) number of files (two files comes first, one file comes second) then (2) length of string, longest first, and be case-insensitive. The first item in the map is your match, assuming it's value (number of files) is 2.

Good luck!
Topic archived. No new replies allowed.