Ex Seashell from exam August 2019
Здравейте,
бих искал да помоля за малко помощ, втори ден се опитвам да разбера нещо което не ме оставя намира.
В judge минава 100/100 но на първият zero test ми дава грешка в броя на stolenshels и ми е интересно, къде греша.
Благодаря на всеки предварително.
https://judge.softuni.bg/Contests/Practice/Index/1781#1
Seashell Treasure
It's beautiful summer afternoon and you decide to go to the beach and collect some seashells. There will be three types of seashells (the most beautiful in the world) - Cockle, Nautilus and Moonshell. But you are not alone at the beach - the Seagull Gully is on his watch and also wants to steal some seashells.
First you will be given the number of rows of the beach - integer n. On the next n lines you will receive the available seashells to collect for each row, separated by single space in the format:
"{seashell1} {seashell2} … {seashelln}"
If there is not a seashell at some positions, the cell is considered empty and will be marked with dash ('-').
After that you will start receiving commands. There are three possibilities:
-
"Collect {row} {col}" - you have to go to the given place if you can and collect the seashell, if there is one. When you collect it, you have to mark the place as an empty, using dash ('-') symbol.
-
"Steal {row} {col} {direction}" - the evil Gully lands at the given coordinates and takes 3 steps in the given direction. He steals the seashells if there are any in the visited cells and also mark them as empty ('-'). If the given coordinates are invalid, Gully cannot land, you are lucky - he doesn't steal seashells and continue circling around. There are four possible directions:
-
"up", "down", "left", "right"
-
"Sunset" - it's getting late and you stop collecting seashells.
In the end, print on the console the last condition of the beach. The cells, containing a seashell or not, should be separated by single space. After that print the count of the seashells you've collected and if they are one or more - list them in order of collecting, separated by comma and space:
"Collected seashells: {countOfCollectedSeashells} -> {seashell1}, {seashell2}, …, {seashelln}"
Last step is to print the number of stolen by Gully seashells in the format:
"Stolen seashells: {countOfStolenSeashells}"
Input
-
On the first line, you will receive the number of beach's rows - integer n
-
On the next n lines, for each row, the situation of the seashells at the beach in the described format above
-
Next, until you receive "Sunset", you will get the commands in the specified format.
Output
-
Print the resulting beach - each cell, separated by single space
-
On the next output line - print information for seashells you've collected in the described format
-
On the last line - print the number of seashells stolen by the seagull
Constraints
-
The number of rows will be positive integer between [1, 10]
-
The types of seashells will always be 'C', 'N', 'M'
-
Move commands will be: "up", "down", "left", "right"
Examples
Input |
Output |
Comment |
6 C N - M C - N - N - - N - M - C N - - - C - M - C M N C M N - C Collect 2 2 Collect 4 1 Steal 3 1 up Collect 4 3 Collect 5 0 Collect 4 0 Steal 2 0 down Sunset
|
C - - M C - N - - - - - - - - C N - - - - - M - C - - - M N - C Collected seashells: 4 -> M, N, C, M Stolen seashells: 4 |
First we receive "Collect" command, we go to the given coordinates and collect the 'M' and leave its cell empty ('-'). At the same way we collect and 'N' for the next command. After that there is "Steal" command - the seagull lands at coordinates 3 1, first collects 'C', then takes 3 steps up - the first cell is empty, so he continues up, on the second step he steals 'N' and on the third - 'N' and sets their cells as empty. The "Collect" command is next, but we don't do anything, because the coordinates are invalid. We execute the last commands in the same way. In the end we print the beach. We've collected 4 seashells, so we print them in order "M, N, C, M". The seagull managed to steal 4 seashells. |
4 - N M C M - - - N Collect 9 0 Collect 1 4 Steal 0 2 right Steal 5 5 up Sunset |
- N - C M - - - N Collected seashells: 0 Stolen seashells: 1 |
The "Collect" commands are skipped, because of the invalid coordinates. When we receive "Steal" command, the seagull steals the 'M', leaves it empty and he can't go 3 steps right, so the program continues. The next command is also "Steal" but the seagull cannot land so he doesn't steal anything. There are no more commands and the program ends. We didn't collect any seashells, so we print the given final messages. |
4
- N M
C
M - - -
N
Steal 0 2 right
Sunset