CCC '03 S1 - Snakes and Ladders

View as PDF

Submit solution

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

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


  • 1
    Tibsmith  commented on Feb. 21, 2019, 2:47 p.m.

    I'm kind of new to java. Does anyone know why i'm having an OLE error? If i remove the sc.HasNext() then i get a IR exception (noSuchElement). Thanks!


    • -1
      JoshuaL  commented on Feb. 21, 2019, 5:54 p.m.

      Seems like you need to take another look at which variables you are comparing with other variables. You as well need some way to output what is needed.


      • 1
        Tibsmith  commented on Feb. 21, 2019, 6:33 p.m.

        thank you but what is causing the IR or OLE on the first case but not the second?


        • 0
          JoshuaL  commented on Feb. 21, 2019, 9:07 p.m.

          I suggest you to reread the questsion


  • 0
    markopolocheno  commented on Feb. 5, 2019, 4:02 p.m.

    Hmm. Why is test case 2 fine, but test case 1 WA ?


  • -1
    iamevanwild  commented on Jan. 6, 2019, 11:29 a.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...


    • 0
      AlanL  commented on Jan. 6, 2019, 4:57 p.m.

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


      • 0
        iamevanwild  commented on Jan. 6, 2019, 8:15 p.m.

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


        • 4
          Rimuru  commented on Jan. 6, 2019, 9:05 p.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).


          • 0
            iamevanwild  commented on Jan. 7, 2019, 12:55 p.m.

            Thank you, found my problem :)


  • -3
    ChickenSlayer22  commented on Dec. 24, 2018, 9:04 p.m.

    I get the first test right, but for the second test, for some reason im getting an out put of "You are on" and i have no idea why. heres my code (C++) https://repl.it/@KirollosB/RoundedWarmheartedSystemsoftware?language=cpp


    • 2
      AlanL  commented on Jan. 6, 2019, 5:02 p.m.

      I think that when 0 is inputted, the break does not work. It only breaks out of your while loop, which goes to your std::cout<<"You Win!";. So basically you are printing You quit and then You win, so instead of using break i suggest using return.


    • -1
      Arihan10  commented on Dec. 25, 2018, 7:16 p.m. edit 3

      Look at the Testcases carefully.

      You are not supposed to print

      You are on square x

      after each input. You are supposed to print all the various 'lines' (e.g You are on square x) after the dice reaches a count of a hundred.

      Also: If on the first line one inputs '8', then it says You are on square 34 instead of 9.


      • 4
        geese  commented on Dec. 26, 2018, 11:27 p.m. edited

        For the record it doesn't matter when you output. The testcase example is just showing you what the final result should look like, it doesn't represent how you get it exactly.


  • -1
    Arihan10  commented on Dec. 24, 2018, 5: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.


    • 1
      kingW3  commented on Dec. 24, 2018, 7:37 p.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!"


  • 0
    Ironboy4000  commented on Dec. 17, 2018, 3: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, 6:18 p.m.

      You don't output

      You are now on square 100

      When the result hits 100


      • -2
        Arihan10  commented on Dec. 24, 2018, 5:19 p.m.

        Yes you do. Look at the sample input: it clearly says: You are now on square 100.


        • 1
          kingW3  commented on Dec. 24, 2018, 7:16 p.m.

          I meant he doesn't output it that's why he's not getting AC, not that you shouldn't output it.


  • 0
    SuperCyther  commented on May 27, 2018, 10:50 a.m. edited

    What is "NoSuchElementExeption"? And why do I keep getting it?

    Edit: I found a missing (break;)


  • 0
    sCript  commented on May 24, 2018, 10:41 a.m.

    Your program never terminates.

    You can look here for what each status code means: https://dmoj.ca/about/codes/

    Read the problem statement over again.

    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.


    • 0
      jsumabatz  commented on May 25, 2018, 8:54 a.m.

      You forgot to press the reply button ^-^

      V


  • 0
    jiayeguo  commented on May 23, 2018, 9:45 p.m.

    Help: Why did I get an IR? what does this even mean


  • 2
    willie3838  commented on May 22, 2018, 4:34 p.m. edited

    i like snakes


  • -1
    Y_Yousfi  commented on April 10, 2018, 7:41 a.m.

    can someone tell me what happens in the second case and why its wrong?


    • 1
      KevinLu  commented on April 10, 2018, 11:20 a.m.

      Have you considered what happens if it goes over 100?

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

      • 0
        Y_Yousfi  commented on April 10, 2018, 6:08 p.m.

        yeah i have considered it, just like the example it doesnt go over 91.


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

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


  • 0
    trollakatroll  commented on June 19, 2017, 6:20 p.m. edit 6

    fixed


  • 0
    Pleedoh  commented on May 28, 2017, 5:15 p.m. edited

    fixed


    • 0
      mse387  commented on May 29, 2017, 9:21 a.m.

      Only part of your output is ever shown here.


  • 0
    Pleedoh  commented on May 28, 2017, 4:52 p.m. edited

    ????

    Someone please look at my code, the very first submission. Why is it printing "You Win!" or "You Quit!" before the moves? This doesn't happen in Eclipse, no idea why it's happening here. Please tell me what I'm doing wrong. Am I not using return 0; properly?


    • 0
      mse387  commented on May 29, 2017, 9:22 a.m.

      Make sure your output matches exactly ("win" is not the same as "Win").


      • 0
        Pleedoh  commented on May 29, 2017, 12:32 p.m.

        Got it, thanks


  • -1
    t_han27  commented on Jan. 25, 2017, 6:45 p.m.

    I'm using Python 3.4.2 and I keep on getting WA on the first case. I went on the CCC website and checked the Marking pdf, and my code was perfect. Why is DMOJ doing this?


    • 2
      Kirito  commented on Jan. 25, 2017, 10:26 p.m.

      Your output must match exactly. This includes input prompts.


    • 7
      d  commented on Jan. 25, 2017, 7:43 p.m.

      Your code does not print the second last line in the sample output.


  • 2
    paydayzcool  commented on Dec. 12, 2016, 8:33 p.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?


    • 0
      Kirito  commented on Dec. 12, 2016, 8:54 p.m.

      No.


  • 1
    DKLS2  commented on Dec. 12, 2016, 10:23 a.m. edited

    So I am learning C# and know barely anything. I applied what I learned on this question and I had finished it before in a different language my question is: Why is my c# program so slow? I had seen other answers that looked almost the exact same (different names for variables was about it.) as mine but were around three times faster.

    Am I just comparing apples to oranges?


    • 2
      Xyene  commented on Dec. 12, 2016, 10:24 p.m.

      For problems like these, where your language's startup time accounts for a large portion of your total runtime, using a language running on a virtual machine will tend to give much greater (and oftentimes unpredictable!) runtimes than native languages, or languages with lightweight interpreters (e.g. Python).

      That said, the startup is usually not an issue that pushes submissions over the TLE boundary.


  • -17
    NaziaSatec  commented on Dec. 8, 2016, 12:48 p.m. edit 3

    This comment is hidden due to too much negative feedback. Click here to view it.


    • 5
      AhnafSATEC  commented on Dec. 8, 2016, 1:47 p.m.

      Maybe Hiba doesn't want to be here. Did you consider her feelings before saying that?


  • -6
    1317269576lqy  commented on Nov. 4, 2016, 11:11 a.m.

    This comment is hidden due to too much negative feedback. Click here to view it.


  • -4
    ceongh  commented on Jan. 12, 2016, 2:06 p.m.

    What is the input for the first test case?


    • 1
      wsl1998  commented on Feb. 17, 2016, 10:38 a.m.

      Read the question carefully. It says "If the piece cannot advance the number of squares indicated by the dice, the piece is not moved at all."


  • -4
    aurpine  commented on Dec. 7, 2015, 6:22 p.m. edited

    Why do I keep on getting WA on the first case? :'(

    Edit: Nevermind, got it. :((((


    • 1
      HowAboutNo  commented on Jan. 2, 2016, 8:21 p.m. edited

      Took me a while as well. I kept looking for the wrong number or misspelled word and then I figured it out :(