Thread: Finding Words within a Phrase

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Finding Words within a Phrase

    I am attempting to write a function that will take a string array of words [I know that all the letters that compose the words are within the phrase] and a Phrase[all spaces are removed] and decide which words might be in the phrase together.


    Perhaps an example will illustrate my point:

    Phrase: afox [a fox]
    Words: a ax of ox fox oaf fax

    Example tests: aax [fails because only one a exists]
    aof [Fails because the test phrase is too short]

    Any ideas? I've been trying to figure out a way [not even the best way, just a way] to do it without any success. I even cut out little pieces of paper with the words on them.

    It seems like it would be simple in theory, but there just so many unknowns.

    Thanks Guys!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you know it's only two words? Are you supposed to try multiple #s of words?

    In either way it might not hurt to use something like next_combination or next_permutation, if allowed, to do these sorts of things.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    3
    Quote Originally Posted by tabstop View Post
    Do you know it's only two words? Are you supposed to try multiple #s of words?

    In either way it might not hurt to use something like next_combination or next_permutation, if allowed, to do these sorts of things.
    That's the thing: I have no idea how many words it might be. I can't even say that it will be less than the number of words, because there could be multiple recurrence of a word, i.e. a, the, etc. Additionally, I want to find all the possibilities, not just one.

    Anything's allowed. It's not an assignment; just a personal project. I'll take a look at next_*.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginners Contest #2 For those who wanted more!!
    By ILoveVectors in forum Contests Board
    Replies: 16
    Last Post: 08-12-2005, 12:03 AM
  2. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  3. phrase to words ?
    By stalker in forum C++ Programming
    Replies: 7
    Last Post: 01-19-2004, 05:18 PM
  4. using strlen and finding shortest and longest words
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 09-30-2001, 06:09 PM