Advertisement
This is comment for paste
02. Fishing Competition - 3
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ******* TASK CONDITION ******* #
- You are a longtime captain of an old fishing vessel.
- The new fishing season begins and you prepare your ship to set sail in search of the big catch…
- You will be given an integer n for the size of the fishing area with a square shape.
- On the next n lines, you will receive the rows of the fishing area.
- You will be placed in a random position, marked with the letter 'S'.
- There will be fishing passages on random positions, marked with a single digit.
- There will be whirlpools marked with 'W'.
- All of the empty positions will be marked with '-'.
- Each turn until the "collect the nets" command is received you will be given commands for your movement.
- Move commands will be: "up", "down", "left", and "right".
- • If you move to a fish passage,
- you collect the amount equal to the digit there, the passage disappears and should be replaced by '-'.
- • If you fall into a whirlpool – the ship sinks and loses its catch, the program ends.
- • If you leave the fishing area (go out of the boundaries of the matrix)
- depending on the move command you will be moved to the opposite side of the one you were on.
- /Example: In a 3x3 matrix you are at position [1,2] and receive the command "right"
- you will be moved to position [1,0]./
- You need at least 20 tons of fish to be considered a successful season.
- Keep in mind that even if the quota is reached the ship continues to move.
- Input
- • On the first line, you are given the integer n – the size of the square matrix.
- • The next n lines hold the values for every row.
- • On each of the next lines, you will get a move command.
- Output
- • On the first line:
- If the ship falls into a whirlpool, print only this message and stop the program:
- o "You fell into a whirlpool! The ship sank and you lost the fish you caught. Last coordinates of the ship: [n,n]"
- If the ship reaches the quota:
- o "Success! You managed to reach the quota!"
- If the ship did not reach the quota:
- o "You didn't catch enough fish and didn't reach the quota! You need {lack of fish} tons of fish more."
- • On the next lines.
- If the catch quantity is bigger than zero, print:
- o "Amount of fish caught: {quantity} tons."
- else: do not print anything.
- If you didn't get into a whirlpool, print the matrix.
- Constraints
- • The size of the square matrix will be between [2…10].
- • Only the letters 'S' and 'W' will be present in the matrix.
- • The fish passages are represented by single positive digits /tons/ between [1…9].
- • It is expected that there will only be either zero or one whirpool present, marked with the letter - 'W'.
- • Your position will be marked with 'S'.
- Examples
- Input
- 4
- ---S
- ----
- 9-5-
- 34--
- down
- down
- right
- down
- collect the nets
- Output
- You didn't catch enough fish and didn't reach the quota! You need 8 tons of fish more.
- Amount of fish caught: 12 tons.
- ----
- ----
- --5-
- S4--
- Comment
- The first command is "down".
- The ship moves to position [1,3] followed by the command "down" [2,3] and then the command "right".
- The ship leaves the matrix's boundaries and transfers to the opposite side at position [2,0].
- The ship comes across a fish passage with a quantity of 9 tons and gets it.
- After executing the third command, the fishing area will appear as follows:
- ----
- ----
- S-5-
- 34--
- Then you receive the command "down" again. You move to the passage of 3 tons and add them to the others 9.
- Your catch is 9 + 3 = 12 tons. In the end, you get the command "collect the nets" and the program ends.
- Input
- 5
- S---9
- 777-1
- W333-
- 11111
- -----
- down
- down
- right
- down
- collect the nets
- Output
- You fell into a whirlpool! The ship sank and you lost the fish you caught. Last coordinates of the ship: [2,0]
- Comment
- The first command is "down". The ship moves to position [1,0] and gets 7 tons of fish.
- Follow the command "down" -> [2,0] The ship falls into a whirlpool and sinks.
- You lose the entire catch and the program ends.
- Input
- 5
- S---9
- 777-1
- --5--
- 11W11
- 988--
- down
- down
- down
- down
- down
- down
- right
- right
- right
- collect the nets
- Output
- Success! You managed to reach the quota!
- Amount of fish caught: 31 tons.
- ----9
- ---S1
- --5--
- -1W11
- -88--
- Comment
- Result is: 7 + 1 + 9 +7 + 7 = 31. You succeeded!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement