CCC '00 S1 - Slot Machines

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2000 Stage 1, Junior #3, Senior #1

Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35^{th} time it is played; the second machine pays 60 quarters every 100^{th} time it is played; the third pays 9 quarters every 10^{th} time it is played.

Input Specification

Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.

Output Specification

Your program should output the number of times Martha plays until she goes broke.

Sample Input


Sample Output

Martha plays 66 times before going broke.


  • -1
    lovebird_blue  commented on Jan. 17, 2023, 7:23 a.m.

    my program works for 1 to 4, but on 5 it just fails? and i have no idea why. does anyone know why it's returning such a high number?

  • 2
    ddpwe  commented on Oct. 22, 2022, 9:05 p.m. edited

    I keep going over and over, it runs properly on my side with the example, but then fails every test. No idea where it's going wrong.

    Edit: I forgot to remove the 2nd comma when I switched to f string, doh! Discord help FTW! Thanx Jello! =)

  • 1
    ethan202107  commented on Oct. 15, 2022, 2:21 p.m. edited

    anyone know whats wrong? i cant seem to find any errors and i also printed out the turns and quarters each time she played to double check if everything is being done properly (yes it was), but it still error?

    example of what my print returned when i was checking:

    input: 48 3 10 4

    machine one turn: 4 machine two turn: 10 machine three turn: 4 quarters left: 47

    • 1
      dumbBusinessman  commented on Oct. 16, 2022, 8:22 p.m.

      you're not resetting the number of times a machine has been used once it pays out quarters.

      • 0
        ethan202107  commented on Oct. 16, 2022, 8:30 p.m.

        ohhhhhh im so stupid thx

  • 0
    20220680  commented on Sept. 12, 2022, 9:09 a.m. edited

    I have tested myself several times and they all get the right answer and when I submit it went wrong for the third test case, Can someone help see which part is having a mistake?

    Oh I know the reason:) a stupid mistake, I messed up the variables

  • 0
    jerrycui07  commented on June 21, 2022, 8:19 p.m. edit 2

    I have tried solving the problem in two different ways . . . the first time, I got the fifth test case wrong, and the second time, I got the second test case wrong. Can someone help me and see what is wrong with my program?

    • 0
      KIRAN  commented on Aug. 18, 2022, 4:12 p.m.

      your looping starts with machine 2 instead for machine 1. May be that is the problem.

    • 0
      nhitchborn  commented on June 25, 2022, 6:48 p.m.

      Look carefully at the if statements you use to determine which machine is in play.

  • 0
    geleto001  commented on April 29, 2022, 7:44 a.m.

    I'm really confused now . My code seems to be fine I tested it 1000 time with different conditions . I was checking every step of the way with the debugger .Everything seems to be fine , but when I submit it , I'm getting error on test 5 !?!?? I'm running out of ideas . Please HELP!!!

  • 10
    Qw3rt7123NobleLion  commented on March 10, 2022, 5:34 p.m.

    all of Martha's life savings are in quarters and now she spent them all...

    • -6
      jerrycui07  commented on June 21, 2022, 8:18 p.m.

      This comment is hidden due to too much negative feedback. Show it anyway.

      • 2
        960t  commented on Nov. 28, 2022, 6:50 p.m.


  • 0
    HuoKnight  commented on March 10, 2022, 3:27 p.m. edited

    When testing with the sample input/output, this passes all tests, but returns 67 when I test the sample input on my own computer, and this returns the correct 66 when run on my own computer, but fails all tests when I submit it. Why is this? It works but I don't know why.

    EDIT: Problem was using >= 0 instead of > 0

  • -2
    hhhhhhhhfhdgshg  commented on Dec. 9, 2021, 9:45 p.m.

    What if she wins and earns more money?

    • 0
      fernandorios  commented on March 6, 2022, 10:45 a.m.

      Rule of las Vegas. The house always wins (unless you know when to quit)

    • 2
      uselessleaf  commented on Dec. 10, 2021, 8:39 a.m.

      Then she uses the earned money on the machines.

  • 0
    bobthesnek63  commented on Nov. 2, 2021, 12:41 p.m.

    I'm not sure if anyone had this problem, but make sure that you output the entire sentence in your output. It is not enough to answer with just a number.

  • -1
    Leaderleade  commented on Feb. 7, 2021, 3:55 p.m.

    PYPY3 failed initializing... Was that a problem with my code or with the judge?

    • 1
      Kirito  commented on Feb. 7, 2021, 4:07 p.m.

      Memory limit is too low for PYPY3, use Python instead.

  • 4
    calluo  commented on Oct. 4, 2020, 6:05 p.m.

    A common problem that those using a while loop may encounter is that Martha's money goes to zero before she gets paid, even though she's supposed to earn money from the machine. The while loop is exited, and your output is incorrect.

  • 4
    cathysun2004  commented on Jan. 10, 2020, 1:22 a.m. edit 2

    Does she alternates between each machine or she just plays it all before going broke?

    • -1
      Neon  commented on Feb. 8, 2020, 11:39 a.m. edited

      "She plays 3 machines in turn"

      • 5
        OneYearOld  commented on Oct. 29, 2020, 8:05 a.m.

        In case you don't know what "in turn" means, she plays the 1st machine, then the 2nd, then the 3rd, and then the 1st and so on.

  • 2
    Julien  commented on Jan. 9, 2020, 8:54 p.m. edited

    On test cases 2 and 3, I seem to be getting 39. Does anyone know what I might be doing wrong?

    • 1
      julian34  commented on April 18, 2021, 7:01 p.m.

      You need to check whether Martha is broke every time she plays. Note that she plays three times with each iteration of the loop, so a simple while (bal > 0) will not suffice.

      If you get WA and have 39 as your output, it's likely that you're not checking often enough. 😉

  • -1
    NathanHuang  commented on Oct. 9, 2018, 8:26 a.m. edited

    What does TLE mean?

  • 1
    Lemonsity  commented on Sept. 14, 2018, 10:05 a.m. edit 3

    My program runs fine for the first four question, but on question five, my program returns 5718 times. I know that is probably wrong, given how big the number is. Can anyone help me? The program isn't that efficient yet, but I just want to get it working for now.

    • 0
      Rimuru  commented on Sept. 14, 2018, 12:20 p.m. edited

      Your error is when the slots repeat (1st slot 35th time, 2ndd slot 100th time, 3rd slot 10th time)