Thread: repeats in a string

  1. #16
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    strSet.insert(variable[string(it,i)]++);
    That should simply be strSet[string(it,i)]++;

    Code:
    i <= data.length() && i <= distance(it,data.end())
    Looking back, you can get rid of the "i <= data.length() &&" part of that... it is not necessary.

    Code:
    for(strSet.begin(),strSet.end(),ostream_iterator<string>(cout,"\n"));
    This is not how a for loop is done. Also, I ran a test using my program and your long test string, I knew the output wasn't going to mean much if sent to cout so I opened an output file and wrote the contents of the map to that. That was a good decision since the file turned out to be 56KB in size. My output code was this:

    Code:
    ofstream output("output.txt");
    for( map<string,int>::iterator it2 = strSet.begin(); it2 != strSet.end(); ++it2 )
        output << it2->second << " - " << it2->first << endl;
    You will need to #include <fstream> to work with files. That will create an output file called output.txt that looks something like (taking some output from my file that was created):

    Code:
    26 - A
    7 - AA
    6 - AAA
    5 - AAAA
    4 - AAAAA
    3 - AAAAAA
    2 - AAAAAAA
    1 - AAAAAAAA
    1 - AAAAAAAAC
    ...
    This is really just for debugging purposes. Your goal now will be to most likely replace the output loop with one that goes throught the map and simply finds the "biggest number of repeats" as you put it according to whatever your rules are for determining that.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    18
    hi hk_mp5kpdw, you have been most kind. I apologise for taking your time.I have found your comments and help so helpful. I will have a good look at what you have told me and will get back to you if i dont fully understand anything.

    take care and kind regards

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    18
    hi hk_mp5kpdw, ihave managed to output the results largest first which i wanted to do.

    To improve this program,I have decided to add some human input to the program. Its a little tricky though to implement.

    if the user wants to search a long string of a required 'n' length.
    EG.
    cout << "What length of n would you like to show?"
    cin >> 8.

    output: Show repeats of length '8'.

    I hope you can help hk_mp5kpdw, i ve been thinking about this and stuck.
    I can show you the code i have been working on if you want to see it.

  4. #19
    Registered User
    Join Date
    Feb 2010
    Posts
    1
    If I wanted this to search through 1,000,000 digits of a given number, would this still work? And would it be very efficient/fast?

  5. #20
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by tro95 View Post
    If I wanted this to search through 1,000,000 digits of a given number, would this still work? And would it be very efficient/fast?
    Probably not efficient, as it's roughly O(n^2) as far as I can see.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  6. #21
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    tro95, don't bump 5 year old posts. If you want, you could have made a new post with your question and posted a link to this thread for reference.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM