Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Word-count
Index -> Programming, C -> C Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Analysis Mode




PostPosted: Sun Aug 02, 2009 7:32 pm   Post subject: Re: Word-count

Another method is to use a set (available in the C++ STL). Run through the document and insert every word into the set. All elements in a set are distinct and every insertion will take log N time, where N is the number of elements currently in the set (and is also the maximum number of distinct words in the document), the total run time will be O(M log N), where M is the total number of words.

To handle the count part, you could have a set of pairs, where the first member of the pair is the word and the second member the number of occurrences and have the set sort by the first element.
Sponsor
Sponsor
Sponsor
sponsor
Icharus




PostPosted: Tue Aug 04, 2009 1:42 pm   Post subject: RE:Word-count

No worries on being an "old guy"...I dig appropriate words. Concordance is much shorter than my previous description.
Also, thanks a ton on the clarification of the O M N variables--that's a nifty little formula.
Analysis: I think that's a great way to do it, but I'm limited to using C with GCC and YACC. Part of the goal is to make this code as elegant, portable, and modular as possible.
I'll keep the C++ in mind though for future applications. It never hurts to know more!
gianni




PostPosted: Tue Aug 04, 2009 6:04 pm   Post subject: Re: RE:Word-count

Icharus @ Tue Aug 04, 2009 1:42 pm wrote:
Part of the goal is to make this code as elegant, portable, and modular as possible.


Perhaps you might consider using a scripting language (e.g. ruby, python, perl, &c...), as they generally excel in these areas?
Icharus




PostPosted: Thu Aug 06, 2009 2:04 pm   Post subject: Re: Word-count

Gianni,
If you're not careful, you'll have people saying I'm just difficult Smile . I am working on learning C, and only C at the moment--I have some experience with scripting languages, but they're not on my list to improve at the moment. The main reason why I'm learning C is to be as close to the machine code as possible.
I'm trying to really get familiar with the inner workings of the computer, simultaneously, I'm working on developing a habit of elegant and reusable code. It can be done in C. The friend who gave me this assignment showed me his library. It's awe-inspiring.
gianni




PostPosted: Thu Aug 06, 2009 2:30 pm   Post subject: Re: Word-count

Icharus @ Thu Aug 06, 2009 2:04 pm wrote:
Gianni,
If you're not careful, you'll have people saying I'm just difficult Smile . I am working on learning C, and only C at the moment--I have some experience with scripting languages, but they're not on my list to improve at the moment. The main reason why I'm learning C is to be as close to the machine code as possible.
I'm trying to really get familiar with the inner workings of the computer, simultaneously, I'm working on developing a habit of elegant and reusable code. It can be done in C. The friend who gave me this assignment showed me his library. It's awe-inspiring.


Do it up! Also, I'll have to show you some Ruby code, you might just poop yourself because it's so elegant!
wtd




PostPosted: Fri Aug 07, 2009 1:29 am   Post subject: RE:Word-count

And my friend, ruby.h, would like to point out that C and high-level scripting languages are not mutually exclusive.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: