Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

This C++ code is designed to find the longest and second longest compound words from a given input file

Libraries
iostream: Input/output stream handling.
fstream: File stream handling.
unordered_set: Implements an unordered set, which is a collection of unique keys with fast retrieval.
unordered_map: Implements an unordered map, which is a collection of key-value pairs with fast retrieval.
vector: A dynamic array that can resize itself.
chrono: Provides functionality for measuring time durations.

Function: int isConcatenate(string word, unordered_set& st, unordered_map<string,bool>& mp)
This recursive function checks whether a given word can be formed by concatenating other words in the provided set.
The function first checks if the current word is already in the memoization map mp. If it is, the function returns the stored result.
If the word is not in mp, the function iterates through the word, splitting it into a prefix and a suffix.
It then recursively checks if the prefix is in the set st and if the suffix is a concatenate word (by calling the function recursively).
If a valid concatenation is found, the function updates mp[word] to true and returns true.
If no valid concatenation is found, the function updates mp[word] to false and returns false

int main()
The program starts by initializing variables, including an input file stream, sets, maps, and vectors to store words.
The input file ("Input_01.txt") is opened, and words are read from the file and inserted into the unordered set st and vector collection.
The isConcatenate function is called for each word in the collection. If a word is a valid concatenate word, it is compared with the current longest (max1) and second longest (max2) words, and these variables are updated accordingly. The program measures the time taken for the entire process using the library.
Finally, the longest and second longest compound words along with the time taken for the computation are printed to the console.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors