// SuffixListDriver04.cpp // tom bailey 9 mar 06 // Construct and print a suffix list. // tom bailey 17 mar 06 // Construct and print a sorted, thus true, suffix list. // tom bailey 20 mar 06 // Construct a suffix list, then determine the longest // matching substring; print the suffixes with the matching // prefixes. // tom bailey 20 mar 06 // Read the string from a file. #include using std::string; #include using std::cout; using std::cin; #include "SuffixList03.h" using std::endl; #include using std::pair; #include using std::setw; #include "Files.h" using std::istream; int main() { while( true ) { istream & infile = Files::getInfile(); string str; string nextStr; getline( infile, nextStr ); while( infile ) { str += nextStr + " "; getline( infile, nextStr ); } Files::removeInfile( infile ); cout << "String length is " << int( str.length() ) << "." << endl; SuffixList sl( str ); cout << "Suffix list has been constructed." << endl; sl.write( cout, 40 ); cout << endl; pair ssPair = sl.longestMatch(); int match = int( ssPair.first.matchLength( ssPair.second ) ); cout << "Longest internal match is " << match << " characters." << endl; int index1 = int( ssPair.first.beginIter() - str.begin() ); int index2 = int( ssPair.second.beginIter() - str.begin() ); cout << ssPair.first.is_prefix(ssPair.second) << endl; // bool match = cout << setw(8) << index1 << ": "; ssPair.first.write( cout, 120 ); cout << endl; cout << setw(8) << index2 << ": "; ssPair.second.write( cout, 120 ); cout << endl << endl; } return 0; }