## 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 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 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. 30, 2021, 11:09 a.m.

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

• commented on Feb. 6, 2020, 11:32 p.m.

Why does my solution output "You are now on" on test case 2?

• commented on Feb. 13, 2020, 5:42 p.m.

Because it only shows clipped output (i.e a small portion of your output) rather than the full output of your program.

• commented on Aug. 19, 2019, 3:50 p.m.

Hello, I'm using java and getting IE on the first test. Went on CEMC website and when I tested it directly it seemed to work perfectly? Please help!

• commented on Aug. 19, 2019, 7:25 p.m.

Your program has to terminate when you win.

• commented on Aug. 20, 2019, 8:53 p.m.

Omg it works! Thanks so much, this was really vexxing me.

• commented on Aug. 15, 2019, 10:42 a.m.

I checked my code on an online compiler with the same values as the first case, and it works, however I don't see why my output on DMOJ doesn't match.

• commented on Aug. 19, 2019, 8:03 p.m. edited

What happens when one attempts to go past square 100?

The first test case is not the same as the sample test case.

• commented on June 11, 2019, 12:44 a.m. edited

Why I get the case 1 incorrect? I can't figure it out somebody helps me plzzz

• commented on June 11, 2019, 12:51 a.m.

what if it go over 100

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

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

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

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

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

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

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

• 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, 9:04 p.m.

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

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

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

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

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

• commented on Dec. 24, 2018, 5:15 p.m. edit 5

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

• 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 Dec. 24, 2018, 5:19 p.m.

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

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

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

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

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.

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

You forgot to press the reply button ^-^

V

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

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

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

i like snakes

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

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

• 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.
• commented on April 10, 2018, 6:08 p.m.

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

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

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

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

fixed

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

fixed

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

Only part of your output is ever shown here.

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

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

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

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

Got it, thanks

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

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

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

Your output must match exactly. This includes input prompts.

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

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

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

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

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

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

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

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

• commented on Nov. 4, 2016, 11:11 a.m.

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

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

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

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

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

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

• 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 :(