Thread: Pls Help me with this problem...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Pls Help me with this problem...

    Gregorio is very interested in discovering properties of non-negative integers. In one of his mathematical excursions, he tried adding all the digits of a number. Of course he ended up with a new number. He performed the same process using this new number and he got another number. If this process is one repeatedly, he realized that it always converge to a number. For example, the number 12345 converges to 6 and 99999 converges to 9.
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    Gregorio tasked himself in discovering the number of non-negative integers from x to y that converge to a given number z. Help Gregorio develop a program that will automate this task.

    INPUT FORMAT
    The input consists of several input lines. Each input line consists of three non-negative integers: x, y, and z. The numbers x and y are respectively the start and end points of the given range of integers. The number z is the point of convergence.

    OUTPUT FORMAT
    For each input line, output the number of non-negative integers from x to y that converge to z. If
    x > y then output 0.

    SAMPLE INPUT
    0 10 1
    12345 12347 7


    SAMPLE OUTPUT
    2
    1


    Or just give me some clues on how to solve this.. =)) thx..

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Heres a clue, call it a nudge in the right direction if you will...

    "Do some work"

    Then post some kind of effort that shows at least you have bothered to think about how to do it. Instead of just copying and pasting your problem out.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by rogster001 View Post
    Heres a clue, call it a nudge in the right direction if you will...

    "Do some work"

    Then post some kind of effort that shows at least you have bothered to think about how to do it. Instead of just copying and pasting your problem out.
    btw..do you understand what he wants to do? Because, I don't..but it looks like it might be good for a beginner like me to program..

    so x and y are the inputs and z is the result

    but what should we do, or rather do you want to do on x and y

    i get this part
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    but it doesn't make sense with this:



    prolink24
    Pls Help me with this problem...
    Gregorio is very interested in discovering properties of non-negative integers. In one of his mathematical excursions, he tried adding all the digits of a number. Of course he ended up with a new number. He performed the same process using this new number and he got another number. If this process is one repeatedly, he realized that it always converge to a number. For example, the number 12345 converges to 6 and 99999 converges to 9.
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    Gregorio tasked himself in discovering the number of non-negative integers from x to y that converge to a given number z. Help Gregorio develop a program that will automate this task.

    INPUT FORMAT
    The input consists of several input lines. Each input line consists of three non-negative integers: x, y, and z. The numbers x and y are respectively the start and end points of the given range of integers. The number z is the point of convergence.

    OUTPUT FORMAT
    For each input line, output the number of non-negative integers from x to y that converge to z. If
    x > y then output 0.

    SAMPLE INPUT
    12345 12347 7


    SAMPLE OUTPUT
    1

    how did you get 1 as output?
    You ended that sentence with a preposition...Bastard!

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    btw..do you understand what he wants to do?
    mate a post like that gets about one nanosecond of reading time in my case.

    After reading it i see it is purest wofflese, it could be an interesting puzzle if it were explained properly, at present it makes about 0 sense, its like 'so what'? obviously you can expect a number? is there supposed to be some kind of special relationship going on?

    how did you get 1 as output?
    He means essentially 'true or false'

    I think its supposed to (or i would) output each number 'string' tested and then show a 0 or 1 for its result
    it would probably be cool to show each number stepping down to its final figure but that has not been stated as a requirement.
    Last edited by rogster001; 01-18-2011 at 08:46 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by rogster001 View Post
    mate a post like that gets about one nanosecond of reading time in my case.
    harsh..lol

    but yeah, it made sense until the very end..and I am like..wt..f!!
    hopefully the OP clarifies what he wants
    You ended that sentence with a preposition...Bastard!

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Eman View Post
    btw..do you understand what he wants to do? Because, I don't..but it looks like it might be good for a beginner like me to program..
    It's numerology....

    12345 = 1 + 2 + 3 + 4 + 5 = 15 = 1 + 5 = 6

    1900 + 45 = 1945 = 1 + 9 + 4 + 5 = 19 = 1 + 9 = 10 = 1 + 0 = 1

    You keep adding the individual digits of a number until you resolve (converge) it to a single digit number...
    Last edited by CommonTater; 01-18-2011 at 08:51 AM.

  7. #7
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yeah I got that part, I am not sure as to how he got 7 with this:

    12345 12347 7

    perhaps he meant 9?
    You ended that sentence with a preposition...Bastard!

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, he got 1 with that, not 7. (Remember, the output is a count, not the result of any particular recursive sum.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    the reason I am asking is that..if 1 and 0 are the respective output
    why was is
    Sample Output 2 for the first input?
    You ended that sentence with a preposition...Bastard!

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Eman
    the reason I am asking is that..if 1 and 0 are the respective output
    why was is
    Sample Output 2 for the first input?
    Because the recursive sum of the digits of 1 and 10 are both 1, hence the count is 2.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by laserlight View Post
    Because the recursive sum of the digits of 1 and 10 are both 1, hence the count is 2.
    yeah..so the count for this:
    12345 12347 7
    is 0?
    You ended that sentence with a preposition...Bastard!

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No, it is 1. I don't know (and don't care) which of 12345, 12346 and 12347 is the one, but whatever it is it took me about 2 minutes to write and run a program to determine that the answer was 1. Do the same and modify it to find out.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oh, I see.
    now while it took you 2mins..give me 20hrs
    You ended that sentence with a preposition...Bastard!

  14. #14
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Ok.. i managed to do it..the most inefficient way but it works..

    so if x > y output 0
    otherwise I should output the count?
    You ended that sentence with a preposition...Bastard!

  15. #15
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    thank you for trying to solve this problem.. but can you pls tell me how you solved this?? because i don't have an idea how to solve this..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pls help with this tutorial problem
    By pelisa in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2010, 11:47 AM
  2. minor problem in up down counter - pls help
    By bondage in forum C Programming
    Replies: 15
    Last Post: 01-15-2010, 01:42 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 01:40 AM