Thread: Word unscrambling

  1. #16
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Well the file is large so I found the largest one I could (12 charectors) but said 15 to be sure. Sorry if this complicates things I didn't realise how important it is. I though it was like when you declare integers larger then you need to prevent overflows.

    No we haven't studied letter frequency counter.

    Thanks again.

  2. #17
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    The reason why the length of the largest word to be unscrambled is important is due to the time complexity problem.

    If you are using a brute force, i.e a permutation generator then a word with 12 letters in it would take a long time to solve.

    Whereas, with a letter frequency counter can solve any word of any length.

  3. #18
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    I see. So this means that my program will take along time to solve all ten?

  4. #19
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> I see. So this means that my program will take along time to solve all ten?

    That totaly depends.

  5. #20
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Yes, since if you use a permutation generator, then by its very nature you are using a brute force algorithm.

    The concept of Letter Frequency counting is explained here:

    http://www.codeproject.com/cpp/Jumble.asp

    Which is initially where I got my idea to create an efficient word unscrambling utility.

  6. #21
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Ok. From one of your previous posts, you said to use

    Code:
    char word[MAX_WORD_SIZE][FILE_SIZE];
    ifstream b_file;
    int i;
    for(i =0; i < FILE_SIZE; i++)
    b_file.in >> word[i];
    This is what I think each line means.

    First line - Declare a char variable with the size of the largest word and the size of the file with the unscrambled words (i think)

    second line - Open the unscramble file
    third line - declare i as an integer variable
    fourth line - Set i as o, as long as i is smaller then the file size, increase i by 1 each loop
    fifth - Not sure. I think it sets the variable "word" to read the next string every loop. Is that right?


    P.S - Thanks treenef I'll read this page through and hopefuly understand it.
    Last edited by pukebucket; 01-07-2006 at 10:54 AM.

  7. #22
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    char word[MAX_WORD_SIZE][FILE_SIZE];
    Do you have to use char arrays or string literals?


    ***If you have any problems post them here. I've done this before.

    What I'd recommend is you read that link and think about a solution to your problem. When you have given it enough thought. Come back here.

    Reading files in and out is not a problem. Worry about that later.
    Last edited by treenef; 01-07-2006 at 10:56 AM.

  8. #23
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Thank you so much This page looks very useful. He didn't specify how to do it, he just told us to do how ever we want :S

    I'll do as you said and come back if I need more help. Once again, thank you so much it really is alot to me.

  9. #24
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    I've run into a problem. At

    Code:
    for (vai = all->begin(); vai != all->end(); vai++, cnt++)			
    cout << cnt + 1 << " " << *vai << endl;			
    char *strcpy ( char ans, const char *vai );                             
    ofstream a_file ( "answer.txt", ios::app );
    a_file<< *vai <<",";
    a_file.close();
    it messes up. I tried to make it write the answers to the text file, but it always ends up being squares. I think it's becuase it's writing the memory address to the file so I tried writing vai without the asterix. But it wont compile. Does anyone know why?
    Thanks in advance

  10. #25
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Just hang on a minute there.

    Don't use the code from my link. It's perhaps a little too complicated for you anyway.

    What I wanted you to do was actually read the concept behind a letter frequency counter.

    Here's what you need to think about.

    Let's say I give you a word:-

    Code:
    treenef
    I want you to write a program which will spits out the letter frequency count for a specific word.

    So...
    Code:
    t = 1
    r = 1
    e =3
    n =1
    f  =1
    And as I've said before don't worry about file input/output until we've finished this.

  11. #26
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    No wait, I didn't copy it. I read the whole thing, and got an understanding of it and then tried to make his one do what my one has to do. His one couldn't write it to a file. I am not going to use his one trust me, my tutor would notice and I would learn nothing from it. I simply want to know how it would write to a file.

  12. #27
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Good, don't use that code.

    I said worry about file input/output later...

    but here's a link anyway
    http://www.cprogramming.com/tutorial/lesson10.html

  13. #28
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    Quote Originally Posted by treenef
    Good, don't use that code.

    I said worry about file input/output later...

    but here's a link anyway
    http://www.cprogramming.com/tutorial/lesson10.html
    That's what I was reading!

  14. #29
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    never mind about that think about the letter frequency counter...

    What have you got?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        char array[100]="treenef";
        
        cout<<array[0];
        cout<<array[1];
        
        //letter count prog goes here
        
        cin.get();
        return 0;
    }

  15. #30
    Registered User
    Join Date
    Jan 2006
    Posts
    19
    I don't quite understand it, so I'm going to re-read it quick.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Using 'if' with char arrays or string objects
    By c++_n00b in forum C++ Programming
    Replies: 36
    Last Post: 06-06-2002, 09:04 PM