petarkobakov

Present Delivery

Oct 24th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.72 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Present_Delivery
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int presents = int.Parse(Console.ReadLine());
  10. int n = int.Parse(Console.ReadLine());
  11. int rows = n;
  12. int cols = n;
  13. char[,] table = new char[rows, cols];
  14. int sRow = 0;
  15. int sCol = 0;
  16. int niceKidsWithPresents = 0;
  17.  
  18.  
  19.  
  20. for (int row = 0; row < rows; row++)
  21. {
  22. char[] currentRow = Console.ReadLine().ToCharArray();
  23.  
  24. for (int col = 0; col < cols; col++)
  25. {
  26. table[row, col] = currentRow[col];
  27.  
  28. if (table[row, col] == 'S')
  29. {
  30. sRow = row;
  31. sCol = col;
  32. }
  33.  
  34.  
  35. }
  36. }
  37.  
  38. string command = Console.ReadLine();
  39.  
  40. while (command!= "Christmas morning" || presents > 0)
  41. {
  42.  
  43.  
  44. //If the cell has 'X' on it, that means there lives a naughty kid.
  45. //if a nice kid lives there, the cell is marked by 'V'.
  46. //marked with 'C' for cookies.
  47. //All of the empty positions will be marked with '-'.
  48.  
  49. switch (command)
  50. {
  51.  
  52. case "up":
  53.  
  54. table[sRow, sCol] = '-';
  55. sRow -= 1;
  56.  
  57. if (sRow < 0)
  58. {
  59. sRow = rows - 1;
  60. }
  61.  
  62. if (table[sRow, sCol] == 'C')
  63. {
  64. table[sRow, sCol] = 'S';
  65.  
  66. if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
  67. {
  68. if (table[sRow + 1, sCol] == 'V')
  69. {
  70. niceKidsWithPresents++;
  71. }
  72.  
  73. presents--;
  74. }
  75. if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
  76. {
  77. if (table[sRow + 1, sCol] == 'V')
  78. {
  79. niceKidsWithPresents++;
  80. }
  81. presents--;
  82. }
  83. if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
  84. {
  85. if (table[sRow + 1, sCol] == 'V')
  86. {
  87. niceKidsWithPresents++;
  88. }
  89.  
  90. presents--;
  91. }
  92.  
  93. if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
  94. {
  95. if (table[sRow + 1, sCol] == 'V')
  96. {
  97. niceKidsWithPresents++;
  98. }
  99. presents--;
  100. }
  101. }
  102.  
  103. if (table[sRow,sCol] == 'V')
  104. {
  105. niceKidsWithPresents++;
  106. presents --;
  107. table[sRow, sCol] = 'S';
  108. }
  109.  
  110. if (table[sRow, sCol] == 'X')
  111. {
  112. table[sRow, sCol] = 'S';
  113. }
  114.  
  115. break;
  116.  
  117. case "down":
  118. table[sRow, sCol] = '-';
  119. sRow += 1;
  120.  
  121. if (sRow > rows-1)
  122. {
  123. sRow = 0;
  124. }
  125.  
  126. if (table[sRow, sCol] == 'C')
  127. {
  128. table[sRow, sCol] = 'S';
  129.  
  130. if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
  131. {
  132. if (table[sRow + 1, sCol] == 'V')
  133. {
  134. niceKidsWithPresents++;
  135. }
  136.  
  137. presents--;
  138. }
  139. if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
  140. {
  141. if (table[sRow + 1, sCol] == 'V')
  142. {
  143. niceKidsWithPresents++;
  144. }
  145. presents--;
  146. }
  147. if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
  148. {
  149. if (table[sRow + 1, sCol] == 'V')
  150. {
  151. niceKidsWithPresents++;
  152. }
  153.  
  154. presents--;
  155. }
  156.  
  157. if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
  158. {
  159. if (table[sRow + 1, sCol] == 'V')
  160. {
  161. niceKidsWithPresents++;
  162. }
  163. presents--;
  164. }
  165. }
  166.  
  167. if (table[sRow, sCol] == 'V')
  168. {
  169. niceKidsWithPresents++;
  170. presents--;
  171. table[sRow, sCol] = 'S';
  172. }
  173.  
  174. if (table[sRow, sCol] == 'X')
  175. {
  176. table[sRow, sCol] = 'S';
  177. }
  178. break;
  179.  
  180. case "left":
  181. table[sRow, sCol] = '-';
  182. sCol -= 1;
  183.  
  184. if (sCol < 0)
  185. {
  186. sCol = cols - 1;
  187. }
  188.  
  189. if (table[sRow, sCol] == 'C')
  190. {
  191. table[sRow, sCol] = 'S';
  192.  
  193. if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
  194. {
  195. if (table[sRow + 1, sCol] == 'V')
  196. {
  197. niceKidsWithPresents++;
  198. }
  199.  
  200. presents--;
  201. }
  202. if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
  203. {
  204. if (table[sRow + 1, sCol] == 'V')
  205. {
  206. niceKidsWithPresents++;
  207. }
  208. presents--;
  209. }
  210. if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
  211. {
  212. if (table[sRow + 1, sCol] == 'V')
  213. {
  214. niceKidsWithPresents++;
  215. }
  216.  
  217. presents--;
  218. }
  219.  
  220. if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
  221. {
  222. if (table[sRow + 1, sCol] == 'V')
  223. {
  224. niceKidsWithPresents++;
  225. }
  226. presents--;
  227. }
  228. }
  229.  
  230. if (table[sRow, sCol] == 'V')
  231. {
  232. niceKidsWithPresents++;
  233. presents--;
  234. table[sRow, sCol] = 'S';
  235. }
  236.  
  237. if (table[sRow, sCol] == 'X')
  238. {
  239. table[sRow, sCol] = 'S';
  240. }
  241. break;
  242.  
  243.  
  244. case "right":
  245. table[sRow, sCol] = '-';
  246. sCol += 1;
  247.  
  248. if (sCol > cols-1)
  249. {
  250. sCol = cols - 1;
  251. }
  252.  
  253. if (table[sRow, sCol] == 'C')
  254. {
  255. table[sRow, sCol] = 'S';
  256.  
  257. if (table[sRow + 1, sCol] == 'V' || table[sRow + 1, sCol] == 'X')
  258. {
  259. if (table[sRow + 1, sCol] == 'V')
  260. {
  261. niceKidsWithPresents++;
  262. }
  263.  
  264. presents--;
  265. }
  266. if (table[sRow - 1, sCol] == 'V' || table[sRow - 1, sCol] == 'X')
  267. {
  268. if (table[sRow + 1, sCol] == 'V')
  269. {
  270. niceKidsWithPresents++;
  271. }
  272. presents--;
  273. }
  274. if (table[sRow, sCol + 1] == 'V' || table[sRow, sCol + 1] == 'X')
  275. {
  276. if (table[sRow + 1, sCol] == 'V')
  277. {
  278. niceKidsWithPresents++;
  279. }
  280.  
  281. presents--;
  282. }
  283.  
  284. if (table[sRow + 1, sCol - 1] == 'V' || table[sRow + 1, sCol - 1] == 'X')
  285. {
  286. if (table[sRow + 1, sCol] == 'V')
  287. {
  288. niceKidsWithPresents++;
  289. }
  290. presents--;
  291. }
  292. }
  293.  
  294. if (table[sRow, sCol] == 'V')
  295. {
  296. niceKidsWithPresents++;
  297. presents--;
  298. table[sRow, sCol] = 'S';
  299. }
  300.  
  301. if (table[sRow, sCol] == 'X')
  302. {
  303. table[sRow, sCol] = 'S';
  304. }
  305. break;
  306.  
  307.  
  308. default:
  309. break;
  310. }
  311.  
  312. command = Console.ReadLine();
  313. }
  314.  
  315. }
  316.  
  317.  
  318.  
  319. private static void PrintTable(int rows, int cols, char[,] table)
  320. {
  321. for (int row = 0; row < rows; row++)
  322. {
  323. for (int col = 0; col < cols; col++)
  324. {
  325. Console.Write(table[row, col]);
  326. }
  327.  
  328. Console.WriteLine();
  329. }
  330. }
  331. }
  332. }
  333.  
Advertisement
Add Comment
Please, Sign In to add comment