Thread: Please help this algorithm. "Longest word"

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Please help this algorithm. "Longest word"

    How can I solve this problem?
    Please help me solve this problem.
    By pseudo-code.

    Please makes it easy to understand.
    I can't solve this problem. Because I just learned basic programming.

    Thank You! so much

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Looks like homework... If the person who assigned it to you thinks you should be capable of it then I don't see why we should think any different.

    This is pretty straight forward in pseudo-code... just consider the following:

    1. How would you define a "word" as it pertains to text in a paragraph.
    2. How would you eliminate characters that aren't part of the words.
    3. How would you check each word one at a time.

    There is nothing in this problem that would require anything more than "basic programming." The general rule about how these things work on this forum, though, is that you give it your best try, post it, and we'll critique you if we feel it will not harm your studies (or we just don't care).
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I disagree, I doubt very much this is homework. It looks like an assignment in the ACM ICPC programming contest, and if there's any professor steasling those assignments to give as homework... Well, that'd be strange: he should at least edit it to fit in his own course.
    Actually, last time I saw a problem named "X" it was during the test phase, where they give three extremely easy problems (X, Y, Z) so you can test how the system works...

    About the algorithm. Well, it's fairly straightforward: Scan the text in a single pass, detect any start-of-word and end-of-word character and for each of those pairs detect the length. If the length is longer than your current maximum then store it. Finally, output what you have stored.

    As you see, the description of the algorithm is little more than the description of the problem. That's how straightforward it is. Have a go at it or ask a more specific question. Try to do as much of it as you can first, though.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    I don't see how referring to a programming contest in the input text somehow makes it unsuitable for college coursework... and teachers rip assignments from programming contests all of the time.

    The fact is, people who actively look for programming assignments on the internet to improve their skills don't give up without an attempt and post the problem on a programming forum asking for a complete solution.
    Sent from my iPadŽ

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I can't solve this problem. Because I just learned basic programming.
    So learn to crawl faster, then learn to walk, before trying to run.

    Pick problems which are just out of range of your current skill, so you learn one new thing with each problem you solve.

    Simply giving you the answer here won´t change how fast you actually learn.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM