CCC '03 S1 - Snakes and Ladders

View as PDF

Submit solution

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

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

Here (see illustration) is a game board for the game Snakes and Ladders. Each player throws a pair of dice to determine how many squares his/her game piece will advance. If the piece lands on the bottom of a ladder, the piece moves up to the square at the top of the ladder. If the piece lands on the top of a snake, the piece "slides" down to the square at the bottom of the snake. If the piece lands on the last square, the player wins. If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all.

In order to help you play this game via a cell phone while travelling, you will write a program that simulates your moves on the board shown and, of course, runs on your handheld computer. You will repeatedly throw the dice and enter the result into the program. After each throw, the program will report the number of the square where your piece lands.

When the program starts it should assume the piece is on square 1. It should repeatedly read input from the user (a number between 2 and 12) and report the number of the square where the piece lands. In addition, if the piece moves to the last square, the program should print You Win! and terminate. If the user enters 0 instead of a number between 2 and 12, the program should print You Quit! and terminate.

For clarity, you are to use the board pictured above and you should note that the board has 3 snakes (from 54 to 19, from 90 to 48 and from 99 to 77) and 3 ladders (from 9 to 34, from 40 to 64 and from 67 to 86).

Sample Input

9
11
12
7
3
5
10
9

Sample Output

You are now on square 10
You are now on square 21
You are now on square 33
You are now on square 64
You are now on square 86
You are now on square 91
You are now on square 91
You are now on square 100
You Win!

Comments


  • 3
    Eddie671829  commented on Nov. 12, 2022, 11:17 p.m.

    so if your end square is bigger than 100 then you go back to the square you came from right?


    • 5
      fireheartjerry  commented on Nov. 13, 2022, 12:47 a.m.

      "If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all."

      If your current tile + current roll is larger than 100, then you do not move.


      • 3
        Eddie671829  commented on Nov. 13, 2022, 3:57 a.m.

        thank you!


  • 3
    20220680  commented on Sept. 21, 2022, 9:20 p.m.

    Ok I found that perhaps for python, dmoj doesn't accept you end the program by exit() statement, and as long as I change it to break it works.


    • 5
      XTL  commented on Sept. 21, 2022, 11:34 p.m. edited

      You need to "import sys" at the beginning of your code and the command is "sys.exit()".


  • 1
    QooModa  commented on May 10, 2022, 6:08 p.m.

    Can anybody help, please?

    I have no idea what's wrong with my code.


  • 1
    hennyyanhappy  commented on April 5, 2022, 8:57 p.m.

    Can someone tell me what's wrong with my code? I get IR for test case 1 and AC for test case 2.


    • 2
      andy_zhu23  commented on April 5, 2022, 9:18 p.m.

      place -= x, instead of place -= 10 in while place > 100


  • 1
    kylew85  commented on Feb. 12, 2022, 9:41 p.m.

    why doesn't my code work at all


    • 2
      Spitfire720  commented on Feb. 12, 2022, 11:12 p.m.

      You didn't capitalize the "you"


      • 3
        Haoyun  commented on April 25, 2022, 2:03 p.m.

        When you think for years, and your code is right, but it's only one letter that is wrong in the output and you smash your computer. ╰(‵□′)╯


  • 1
    andrek  commented on Jan. 9, 2022, 4:05 a.m.

    why am i getting AC on the second case but WA on the first case?


    • 2
      Spitfire720  commented on Jan. 9, 2022, 4:41 p.m.

      You still have to print what square you're on when you win.


  • 1
    cchungelliot  commented on Jan. 1, 2022, 7:34 p.m. edit 4

    I got OLE on first case and AC on second. Why I get OLE on first when it work on VSC. C++20 .edit : I fix it. edit 2: still OLE


    • 1
      Spitfire720  commented on Jan. 1, 2022, 8:48 p.m.

      I haven't really coded in C++, but your code doesn't terminate when you win the game.


  • 1
    IDontKnowWhatUsername  commented on Sept. 20, 2021, 12:59 p.m.

    Can somebody look at my code and tell me what's wrong with my formatting, I am getting the correct outputs.


    • 3
      Kirito  commented on Sept. 21, 2021, 2:28 a.m.

      The java.util.NoSuchElementException exception hints that the error is not in your formatting, but rather that your Scanner is trying to read past the end of the input.

      Notice that the input only contains a single game, and your program is expected to terminate itself (without errors) at the end of the game.


  • -1
    dchoo333  commented on Sept. 4, 2021, 11:38 a.m.

    Why am I getting WA on the second case but AC on the first case?


    • 1
      henrybaolol9  commented on Sept. 8, 2021, 8:23 p.m.

      its 9 -> 34 not 12 -> 34


      • 1
        dchoo333  commented on Sept. 19, 2021, 4:39 a.m.

        Thanks.


  • 1
    Summation  commented on May 3, 2021, 5:16 p.m.

    To clarify, for this problem, do we print the square the player is on after each input, or do we continue taking inputs until the player either wins or loses and THEN print the squares they were on? Thank you.


    • 2
      heidihon  commented on May 3, 2021, 7:12 p.m.

      I'm pretty sure either should work.


  • 1
    NoOneofConsequence  commented on Feb. 7, 2021, 9:11 p.m.

    Does anyone know why for my code, although test case #2 is correct, test case #1 is OLE?


    • 1
      cchungelliot  commented on Jan. 1, 2022, 7:35 p.m.

      yeah same with me


    • 6
      Kirito  commented on Feb. 7, 2021, 10:08 p.m.

      You've confused a snake for a ladder.


  • 0
    evanwild  commented on Jan. 6, 2019, 4:29 p.m.

    Does anyone know why my code produces two WAs? I have tested a bunch of times and I can't find any wrong output from my program...


    • 1
      AlanL  commented on Jan. 6, 2019, 9:57 p.m.

      Your code doesn't show what square the player is currently on.


      • 1
        evanwild  commented on Jan. 7, 2019, 1:15 a.m.

        Am I supposed to print everything at the end, or print their position immediately after each input?


        • 7
          Rimuru  commented on Jan. 7, 2019, 2:05 a.m.

          This does not matter. Everything is redirected to an output file, which is checked after your code has completed. As long as the output is correct, the time of when you output is irrelevant. (Different case for interactive problems).


          • 1
            evanwild  commented on Jan. 7, 2019, 5:55 p.m.

            Thank you, found my problem :)


  • -4
    Arihan10  commented on Dec. 24, 2018, 10:15 p.m. edit 5

    EDIT:

    Now my first Testcase works fine, meaning that it now says AC, however, my second Testcase still says WA.

    Does anyone know why I am getting this? Here is my output for Testcase 2 (clipped):

    You Quit!

    Thank you.


    • 3
      kingW3  commented on Dec. 25, 2018, 12:37 a.m. edit 6

      EDIT: If the test case is something like

      3
      4
      0

      You should output

      You are now on square 4
      You are now on square 8
      You Quit!

      But you just output "You Quit!"


  • 1
    Ironboy4000  commented on Dec. 17, 2018, 8:54 p.m. edited

    Can somebody give me a hint as to why my code does not work? When testing it, I did not find any errors in spelling, or numbers, but for some reason the first input is wrong? Please help, thanks.


    • 1
      kingW3  commented on Dec. 17, 2018, 11:18 p.m.

      You don't output

      You are now on square 100

      When the result hits 100


  • 2
    jpr4  commented on Jan. 30, 2018, 8:40 p.m.

    The snake reminds me Getting Over It with Bennett Foddy. :(


  • 1
    paydayzcool  commented on Dec. 13, 2016, 1:33 a.m.

    If the user enters 0 instead of a number between 2 and 12, the program should print You Quit! and terminate.

    Will there be a test case where the user will input 1 or something higher than 12?


    • -2
      Kirito  commented on Dec. 13, 2016, 1:54 a.m.

      No.