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!
Comments
so if your end square is bigger than 100 then you go back to the square you came from right?
"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.
thank you!
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.
You need to "import sys" at the beginning of your code and the command is "sys.exit()".
Can anybody help, please?
I have no idea what's wrong with my code.
Can someone tell me what's wrong with my code? I get IR for test case 1 and AC for test case 2.
place -= x, instead of place -= 10 in while place > 100
why doesn't my code work at all
You didn't capitalize the "you"
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. ╰(‵□′)╯
why am i getting AC on the second case but WA on the first case?
You still have to print what square you're on when you win.
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
I haven't really coded in C++, but your code doesn't terminate when you win the game.
Can somebody look at my code and tell me what's wrong with my formatting, I am getting the correct outputs.
The
java.util.NoSuchElementException
exception hints that the error is not in your formatting, but rather that yourScanner
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.
Why am I getting WA on the second case but AC on the first case?
its 9 -> 34 not 12 -> 34
Thanks.
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.
I'm pretty sure either should work.
Does anyone know why for my code, although test case #2 is correct, test case #1 is OLE?
yeah same with me
You've confused a snake for a ladder.
Got it, thank you so much!
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...
Your code doesn't show what square the player is currently on.
Am I supposed to print everything at the end, or print their position immediately after each input?
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).
Thank you, found my problem :)
EDIT:
Now my first
Testcase
works fine, meaning that it now saysAC
, however, my secondTestcase
still saysWA
.Does anyone know why I am getting this? Here is my output for
Testcase 2 (clipped)
:You Quit!
Thank you.
EDIT: If the test case is something like
You should output
But you just output "You Quit!"
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.
You don't output
When the result hits 100
The snake reminds me Getting Over It with Bennett Foddy. :(
Will there be a test case where the user will input 1 or something higher than 12?
No.