Advertisement
bullit3189

The Garden

Jun 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. int rows = int.Parse(Console.ReadLine());
  12.  
  13. char[][] jagged = new char[rows][];
  14.  
  15. for(int row=0; row<rows; row++)
  16. {
  17. string input = Console.ReadLine().Replace(" ","");
  18. char[] currRow = input.ToCharArray();
  19.  
  20. jagged[row] = new char[currRow.Length];
  21.  
  22. for(int col =0; col<jagged[row].Length; col++)
  23. {
  24. jagged[row][col] = currRow[col];
  25. }
  26. }
  27.  
  28. int carrots = 0;
  29. int potatos = 0;
  30. int lettuces = 0;
  31. int harmed = 0;
  32.  
  33. while(true)
  34. {
  35. string command = Console.ReadLine();
  36.  
  37. if(command == "End of Harvest")
  38. {
  39. break;
  40. }
  41.  
  42. string[] tokens = command.Split(new string[]{" "},StringSplitOptions.RemoveEmptyEntries);
  43.  
  44. if(tokens.Length==3)
  45. {
  46. int harvestRow = int.Parse(tokens[1]);
  47. int harvestCol = int.Parse(tokens[2]);
  48.  
  49. if(harvestRow>=0 && harvestRow<rows && harvestCol>=0 && harvestCol<jagged[harvestRow].Length)
  50. {
  51. if(jagged[harvestRow][harvestCol]=='C')
  52. {
  53. jagged[harvestRow][harvestCol]=' ';
  54. carrots++;
  55. }
  56. else if (jagged[harvestRow][harvestCol]=='P')
  57. {
  58. jagged[harvestRow][harvestCol]=' ';
  59. potatos++;
  60. }
  61. else if (jagged[harvestRow][harvestCol]=='L')
  62. {
  63. jagged[harvestRow][harvestCol]=' ';
  64. lettuces++;
  65. }
  66. }
  67. }
  68. else
  69. {
  70. int moleRow = int.Parse(tokens[1]);
  71. int moleCol = int.Parse(tokens[2]);
  72. string direction = tokens[3];
  73.  
  74. if(moleRow>=0 && moleRow<rows && moleCol>=0 && moleCol<jagged[moleRow].Length)
  75. {
  76. if(direction=="up")
  77. {
  78. while(moleRow>=0)
  79. {
  80. if(jagged[moleRow][moleCol]=='P' || jagged[moleRow][moleCol]=='C' || jagged[moleRow][moleCol]=='L')
  81. {
  82. jagged[moleRow][moleCol]=' ';
  83. harmed++;
  84.  
  85. }
  86. moleRow-=2;
  87. }
  88. }
  89. else if (direction == "down")
  90. {
  91. while(moleRow<rows)
  92. {
  93. if(jagged[moleRow][moleCol]=='P' || jagged[moleRow][moleCol]=='C' || jagged[moleRow][moleCol]=='L')
  94. {
  95. jagged[moleRow][moleCol]=' ';
  96. harmed++;
  97.  
  98. }
  99. moleRow+=2;
  100. }
  101. }
  102. else if (direction == "left")
  103. {
  104. while(moleCol>=0)
  105. {
  106. if(jagged[moleRow][moleCol]=='P' || jagged[moleRow][moleCol]=='C' || jagged[moleRow][moleCol]=='L')
  107. {
  108. jagged[moleRow][moleCol]=' ';
  109. harmed++;
  110.  
  111. }
  112. moleCol-=2;
  113. }
  114. }
  115. else if (direction == "right")
  116. {
  117. while(moleCol<jagged[moleRow].Length)
  118. {
  119. if(jagged[moleRow][moleCol]=='P' || jagged[moleRow][moleCol]=='C' || jagged[moleRow][moleCol]=='L')
  120. {
  121. jagged[moleRow][moleCol]=' ';
  122. harmed++;
  123.  
  124. }
  125. moleCol+=2;
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. foreach(var row in jagged)
  133. {
  134. Console.WriteLine(string.Join(" ",row));
  135. }
  136.  
  137. Console.WriteLine("Carrots: {0}",carrots);
  138. Console.WriteLine("Potatoes: {0}",potatos);
  139. Console.WriteLine("Lettuce: {0}",lettuces);
  140. Console.WriteLine("Harmed vegetables: {0}",harmed);
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement