Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. The Garden
  2. Create a program that helps you harvest vegetables. There are three kinds of vegetables in your garden:
  3. Lettuce – 'L', Potatoes – 'P', Carrots – 'C'
  4. First, you will receive the rows of the garden. Then for each row, you will receive the vegetables, separated by space in the following format:
  5. "{vegetable1} {vegetable2} {vegetable3}… {vegetablen}"
  6. Then you will start receiving commands. Here are the possible ones you can receive:
  7. "Harvest {row} {col}" – you must go to the given place in the garden and harvest the vegetable, if it exists. When you harvest a vegetable, you leave an empty space in the cell – ' '. Keep in mind, that you can't harvest a vegetable, which was already harvested or harmed.
  8. "Mole {row} {col} {direction}" – there is a mole in that cell and it goes in that direction, which means the mole, goes from this cell until the last cell in the given direction. It harms the given cell, skips the next, and harms the next one, an so on until the last cell. Mark the harmed cells with a space - ' '. Keep in mind, that you can't harm a vegetable, that was already harmed or harvested. There are four possible directions:
  9. "Up", "Down", "Left", "Right"
  10. "End of Harvest" – ends the input.
  11. Here is an example of the mole's harm radius:
  12.  
  13. In the end, print the resulting garden. The cells must be separated by a space. Then print the vegetbles you have succesfully harvested and the count of harmed vegetables you have found in the following format:
  14. "Carrots: {countOfCarrots}
  15. Potatos: {countOfPotatos}
  16. Lettuce: {countOfCucmbers}
  17. Harmed vegetables: {count}"
  18. Input / Constraints
  19. On the first line, you will receive the count of rows.
  20. On the next lines, for each row, you will receive the vegetables in the described format.
  21. Next, until you receive "End of Harvest", you will be receiving commands in the described format.
  22. The input will always be valid and you don't need to check it explicitly.
  23. Output
  24. Print the resulting garden – each cell separated by a single space.
  25. Print the harvested and harmed vegatables in the format described above.
  26. Examples
  27. Input
  28. Output
  29. Comment
  30.  
  31. 4
  32. L P C L L
  33. L L C P P P
  34. C C C C
  35. P C L P C L P C L
  36. Harvest 0 2
  37. Harvest 3 0
  38. Harvest 4 2
  39. Mole 2 2 up
  40. Mole 1 1 right
  41. End of Harvest
  42. L P L L
  43. L C P
  44. C C C
  45. C L P C L P C L
  46. Carrots: 1
  47. Potatoes: 1
  48. Lettuce: 0
  49. Harmed vegetables: 4
  50. When we receive the "Harvest" command, we go to the given coordinates and harvest the 'C' and leave an empty space ' '. After that, we go to the 'P' on 3 0 and we take it. After that we receive invalid coordinates, so we don't do anything. Upon receiving the mole command, we harm the vegetable in its cell and every vegetable in the described way – harm the current cell, skip the next and this repeats until the end of the row/coll. We leave empty spaces in the cells. In the end, we have 4 harmed vegetables, one harvested carrot and one harvested potato.
  51.  
  52. 3
  53. P L C
  54. C C C C C C
  55. L L P P P L L L
  56. Harvest 0 0
  57. Harvest 1 3
  58. Mole 2 0 up
  59. Harvest 2 5
  60. Harvest 1 1
  61. Harvest 0 2
  62. Harvest 1 4
  63. End of Harvest
  64. L
  65. C C C
  66. L P P P L L
  67. Carrots: 4
  68. Potatoes: 1
  69. Lettuce: 1
  70. Harmed vegetables: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement