Advertisement
Guest User

withChar

a guest
Feb 20th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 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 Excercises
  8. {
  9. class Excercises
  10. {
  11.  
  12. private static int _n = 0;
  13. private static String _text = "";
  14. private static int _textIndex = 0;
  15. private static char[,] _matrix;
  16. private static int _startCol;
  17. private static int _endCol;
  18. private static int _startRow;
  19. private static int _endRow;
  20. private static int _flag = 0;
  21.  
  22. static void Main(string[] args)
  23. {
  24. _n = int.Parse(Console.ReadLine());
  25. _text = Console.ReadLine();
  26.  
  27. //matrix
  28. _matrix = new char[_n, _n];
  29.  
  30. _startCol = 0;
  31. _endCol = _n - 1;
  32. _startRow = 0;
  33. _endRow = _n - 1;
  34.  
  35. while (!isDone())
  36. {
  37. _flag = iterateRight();
  38. if (isDone())
  39. {
  40. break;
  41. }
  42.  
  43. _flag = iterateDown();
  44. if (isDone())
  45. {
  46. break;
  47. }
  48.  
  49. _flag = iterateLeft();
  50. if (isDone())
  51. {
  52. break;
  53. }
  54.  
  55. _flag = iterateUp();
  56. if (isDone())
  57. {
  58. break;
  59. }
  60. }
  61.  
  62. // printMatrix();
  63. int[] result = new int[] {0, 0};
  64. int rowWeight = 0;
  65. for (int i = 0; i < _n; i++)
  66. {
  67. rowWeight = 0;
  68. for (int b = 0; b < _n; b++)
  69. {
  70. int pos = char.ToUpper(_matrix[i, b]) - 64;
  71. rowWeight += (pos) * 10;
  72. }
  73.  
  74. if (rowWeight > result[1])
  75. {
  76. result[0] = i;
  77. result[1] = rowWeight;
  78. }
  79. }
  80.  
  81. Console.WriteLine("{0} - {1}", result[0], result[1]);
  82. }
  83.  
  84. private static int iterateRight()
  85. {
  86. if (_matrix[_startRow, _startCol] != '\0')
  87. {
  88. return 1;
  89. }
  90.  
  91. for (int i = _startCol; i <= _endCol; i++)
  92. {
  93. if (_textIndex >= _text.Length)
  94. {
  95. _textIndex = 0;
  96. }
  97.  
  98. _matrix[_startRow, i] = _text[_textIndex];
  99. _textIndex++;
  100. }
  101.  
  102. _startRow++;
  103.  
  104. return 0;
  105. }
  106.  
  107. private static int iterateDown()
  108. {
  109. if (_matrix[_startRow, _endCol] != '\0')
  110. {
  111. return 1;
  112. }
  113.  
  114. for (int i = _startRow; i <= _endRow; i++)
  115. {
  116. if (_textIndex >= _text.Length)
  117. {
  118. _textIndex = 0;
  119. }
  120.  
  121. _matrix[i, _endCol] = _text[_textIndex];
  122. _textIndex++;
  123. }
  124.  
  125. _endCol--;
  126.  
  127. return 0;
  128. }
  129.  
  130. private static int iterateLeft()
  131. {
  132. if (_matrix[_endRow, _endCol] != '\0')
  133. {
  134. return 1;
  135. }
  136.  
  137. for (int i = _endCol; i >= _startCol; i--)
  138. {
  139. if (_textIndex >= _text.Length)
  140. {
  141. _textIndex = 0;
  142. }
  143.  
  144. _matrix[_endRow, i] = _text[_textIndex];
  145. _textIndex++;
  146. }
  147.  
  148. _endRow--;
  149.  
  150. return 0;
  151. }
  152.  
  153. private static int iterateUp()
  154. {
  155. if (_matrix[_startRow, _endCol] != '\0')
  156. {
  157. return 1;
  158. }
  159.  
  160. for (int i = _endRow; i >= _startRow; i--)
  161. {
  162. if (_textIndex >= _text.Length)
  163. {
  164. _textIndex = 0;
  165. }
  166.  
  167. _matrix[i, _startCol] = _text[_textIndex];
  168. _textIndex++;
  169. }
  170.  
  171. _startCol++;
  172.  
  173. return 0;
  174. }
  175.  
  176. private static Boolean isDone()
  177. {
  178. return _flag != 0;
  179. }
  180.  
  181. private static void printMatrix()
  182. {
  183. for (int i = 0; i < _n; i++)
  184. {
  185. for (int b = 0; b < _n; b++)
  186. {
  187. Console.Write(_matrix[i, b]);
  188. }
  189. }
  190.  
  191. Console.Write("\n");
  192. }
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement