Advertisement
Guest User

withString

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