hi, thanks for direction....but after generating the possible permutation...i would loop through the my 30k words in the dictionary to see if the permutation is in the dictionary and then add it to my key, value map.
but if i would to loop through 30k for each permutation, it will be slow i think...are there any better ways of solving this?
jkr
Just add it to the map. A map will not accept any duplicates anyway.
hi eleven_squared,
would you mind explaning while(file >> str) str is = "" how does file know how many bytes to read from the file so that for that n bytes is = to 1 word? what if the dictionary is newline delimited?
thks
eleven_squared
str is a std::string; when reading from the file the string resizes itself to accommodate all chars read till a white space is encountered.
the word in the dictionay could be delimited by any white space (space, tab, newline etc.)
jaxrpc
ASKER
hi, thanks for the tips... i am finding out why some of the things done that way.....
guess i really need to do practise more....i have been learning for 1 month + but i took so long to think of how to do something which you can do within minutes.....
itsmeandnobodyelse
I wouldn't use a multimap (it has really a ugly and uncomfortable interface). Better use a
map<string, vector<string> > permMap;
where the key is the sorted permutation key (unique) and the vector contains all occurences. Read the dictionary file like eleven_sqared had showed (the strings either should be separated by space or by newline), make the sorted key and add it to the map by
permMap[key].push_back(str);
if the key doesn't exist a vector was created. If it exists you'll get a reference to the existing vector. To get the output required you need to iterate the map and iterate each vector inside of the loop as well.
jaxrpc, do not loose heart. it takes time before programming starts looking really easy. everyone would have been in your position when they started out; i certainly was!
jaxrpc
ASKER
itsmeandnobodyelse, i will try out your suggestion too...
eleven squared : looks like the STL is really useful
eleven_squared
yes, stl is really useful. you would find a lot of ways to do things in a much easier way once you are familiar with it.
>>>> to find some info on the pair template...but i found nothing..
class pair is defined in <utility>. Maybe there is a topic in cppreference. You should get it via map as well.
itsmeandnobodyelse
>>>> while (vit1 != v.end())
That line must be removed. I replaced it by the for loop above.