Advertisement
Guest User

Untitled

a guest
May 8th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _3rdProblem
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string line = Console.ReadLine();
  14. string[] array = line.Split(' ');
  15. int r = int.Parse(array[0]);
  16. int c = int.Parse(array[1]);
  17. int[,] matrix = new int[r, c];
  18. int num = 0;
  19.  
  20. for (int i = r - 1; i >= 0; i--)
  21. {
  22. for (int j = 0; j < c; j++)
  23. {
  24. matrix [i,j] = num;
  25. num += 3;
  26.  
  27. }
  28. num = matrix[i, 1];
  29. }
  30.  
  31. //for (int i = 0; i < r; i++)
  32. //{
  33. // for (int j = 0; j < c; j++)
  34. // {
  35. // if (j != c - 1)
  36. // {
  37. // Console.Write(matrix[i, j] + " ");
  38. // }
  39. // else
  40. // {
  41. // Console.Write(matrix[i, j]);
  42. // }
  43. // }
  44. // Console.WriteLine();
  45. //}
  46.  
  47. int iterations = int.Parse(Console.ReadLine());
  48. string[] arr = new string[2];
  49. string command;
  50. int moves;
  51. int sum = 0;
  52. int startRow = r - 1;
  53. int startCol = 0;
  54. List <string> items = new List<string>();
  55. string checkItem;
  56.  
  57.  
  58. for (int ii = 0; ii < iterations; ii++)
  59. {
  60. line = Console.ReadLine();
  61. arr = line.Split(' ');
  62. command = arr[0];
  63. moves = int.Parse(arr[1]);
  64.  
  65.  
  66.  
  67.  
  68. if (command == "UR" || command == "RU")
  69. {
  70.  
  71. for (int i = 0; i < moves; i++)
  72. {
  73. if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
  74. {
  75. startRow++;
  76. startCol--;
  77. break;
  78. }
  79. checkItem = startRow.ToString() + startCol.ToString();
  80. if (items.Contains(checkItem) == false)
  81. {
  82. sum += matrix[startRow, startCol];
  83. items.Add(checkItem);
  84. }
  85. if (i == moves - 1)
  86. {
  87. break;
  88. }
  89. startRow--;
  90. startCol++;
  91.  
  92. }
  93.  
  94.  
  95. }
  96. if (command == "RD" || command == "DR")
  97. {
  98.  
  99. for (int i = 0; i < moves; i++)
  100. {
  101. if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
  102. {
  103. startRow--;
  104. startCol--;
  105. break;
  106. }
  107. checkItem = startRow.ToString() + startCol.ToString();
  108. if (items.Contains(checkItem) == false)
  109. {
  110. sum += matrix[startRow, startCol];
  111. items.Add(checkItem);
  112. }
  113. if (i == moves - 1)
  114. {
  115. break;
  116. }
  117. startRow++;
  118. startCol++;
  119.  
  120. }
  121.  
  122. }
  123. if (command == "DL" || command == "LD")
  124. {
  125. for (int i = 0; i < moves; i++)
  126. {
  127. if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
  128. {
  129. startRow--;
  130. startCol++;
  131. break;
  132. }
  133. checkItem = startRow.ToString() + startCol.ToString();
  134. if (items.Contains(checkItem) == false)
  135. {
  136. sum += matrix[startRow, startCol];
  137. items.Add(checkItem);
  138. }
  139.  
  140. if (i == moves - 1)
  141. {
  142. break;
  143. }
  144.  
  145. startRow++;
  146. startCol--;
  147. }
  148. }
  149.  
  150.  
  151.  
  152. if (command == "UL" || command == "LU")
  153. {
  154. for (int i = 0; i < moves; i++)
  155. {
  156. if (startCol < 0 || startCol >= c || startRow < 0 || startRow >= r)
  157. {
  158. startRow++;
  159. startCol++;
  160. break;
  161. }
  162. checkItem = startRow.ToString() + startCol.ToString();
  163. if (items.Contains(checkItem) == false)
  164. {
  165. sum += matrix[startRow, startCol];
  166. items.Add(checkItem);
  167. }
  168. if (i == moves - 1)
  169. {
  170. break;
  171. }
  172. startRow--;
  173. startCol--;
  174. }
  175.  
  176.  
  177. }
  178.  
  179. }
  180.  
  181. Console.WriteLine(sum);
  182. Console.Read();
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement