Re: speedy gonzales


[ Follow Ups ] [ Post Followup ] [ CS328 Message Board ] [ FAQ ]

Posted by dude on August 17, 2001 at 17:38:36:

In Reply to: speedy gonzales posted by project 5 on August 17, 2001 at 03:27:44:

mine was pretty damn fast, all I did was create an STL map of maps were the outer map used strings for its keys and the inner map also used strings for keys (I should have used a set for the inner object, but I didnt have time, so I just used a map and pretty much ignored the data in the data part). When I read in the data, I ran a mutated version of qSort that I got from the book that would call insertion sort if the string was under 10 chars (since qSort is slower for arrays that under ten indexes long, so needless to say that actually got called more often). I would take this and store it as the key in the outer map and store the unsorted string as the key in the inner map. When I had finished storing everything, I iterated through the outer map, checking the size as I went and stored the first iterator that pointed to the first object that was larger than all the previous ones (since iterator will iterate through the object in order from least to greatest this is very beneficial because in case of a tie, you want the one that comes first). Then I iterated through the inner map that contained all of the most anagrams and output those. It worked and was pretty fast to code.

If you dont already have it, I recommend getting a book called C++ written by some guy whose name I can barely spell: Bjarne Strousup (I think?!?!?!)

This guy pretty much came up with c++ so this book has everything you could ever want about the STL including some EXTREMELY helpful examples.

GOOD LUCK IN THE FUTURE!

-Roel


Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS328 Message Board ] [ FAQ ]