## CCC '03 S1 - Snakes and Ladders

View as PDF

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 . It should repeatedly read input from the user (a number between and ) 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 snakes (from to , from to and from to ) and 3 ladders (from to , from to and from to ).

#### 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!

• commented on Jan. 8, 2022, 11:05 p.m.

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

• commented on Jan. 9, 2022, 11:41 a.m.

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

• commented on Jan. 1, 2022, 2: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

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

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

• commented on Sept. 20, 2021, 8:59 a.m.

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

• commented on Sept. 20, 2021, 10:28 p.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.

• commented on Sept. 4, 2021, 7:38 a.m.

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

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

its 9 -> 34 not 12 -> 34

• commented on Sept. 19, 2021, 12:39 a.m.

Thanks.

• commented on May 3, 2021, 1: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.

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

I'm pretty sure either should work.

• commented on Feb. 7, 2021, 4:11 p.m.

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

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

yeah same with me

• commented on Feb. 7, 2021, 5:08 p.m.

You've confused a snake for a ladder.

• commented on Feb. 8, 2021, 10:07 a.m.

Got it, thank you so much!

• 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...

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

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

• 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?

• 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).

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

Thank you, found my problem :)

• 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.

• 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!"

• 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.

• commented on Dec. 17, 2018, 6:18 p.m.

You don't output

You are now on square 100

When the result hits 100

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

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

• 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?

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

No.