The end of the semester is here and finals week is next week...
So any projects I'm wanting to start are being put on hold so I can pass my 2 part algorithm final... It's the only one I'm really worried about, the other ones will be pieces of cake.
But I have been doing some small and simple programs to make my homework easier... or to just do the monotonous boring parts for me. Like my beginning math class I have to take. We had to go through specific verses of a book and see how many times specific words appeared... No way was I going to actually do that...
for (int i = 99; i >= 0; i--)
{
counts[i] = 0;
int found = -1;
do
{
if(found != -1)
{
counts[i]++;
verse.erase(found, words[i].length());
}
found = (int)verse.find(words[i], found + 1);
}while(found != -1);
}
The c++ string class has some nice features but not quite up to the standard java features. If I had used a vector instead of an array I would have been able to not do any hardcoding on the for loop but since I've been working with arrays quite a bit recently it was just simpler to implement at that specific moment.
It has a little bit of hardcoding and it technically doesn't require the words to be sorted in alphabetically order but it works better if it does, so it takes care of the longer words first if some phrases have other phrases in them.
If I ever have to do an assignment like this again, I'll be way more efficient but throwing this program together probably took about as much time as if I had done the actual looking up each verse.
//END OF LINE
No comments:
Post a Comment