Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Excercises
- {
- class Excercises
- {
- private static int _n = 0;
- private static String _text = "";
- private static int _textIndex = 0;
- private static char[,] _matrix;
- private static int _startCol;
- private static int _endCol;
- private static int _startRow;
- private static int _endRow;
- private static int _flag = 0;
- static void Main(string[] args)
- {
- _n = int.Parse(Console.ReadLine());
- _text = Console.ReadLine();
- //matrix
- _matrix = new char[_n, _n];
- _startCol = 0;
- _endCol = _n - 1;
- _startRow = 0;
- _endRow = _n - 1;
- while (!isDone())
- {
- _flag = iterateRight();
- if (isDone())
- {
- break;
- }
- _flag = iterateDown();
- if (isDone())
- {
- break;
- }
- _flag = iterateLeft();
- if (isDone())
- {
- break;
- }
- _flag = iterateUp();
- if (isDone())
- {
- break;
- }
- }
- // printMatrix();
- int[] result = new int[] {0, 0};
- int rowWeight = 0;
- for (int i = 0; i < _n; i++)
- {
- rowWeight = 0;
- for (int b = 0; b < _n; b++)
- {
- int pos = char.ToUpper(_matrix[i, b]) - 64;
- rowWeight += (pos) * 10;
- }
- if (rowWeight > result[1])
- {
- result[0] = i;
- result[1] = rowWeight;
- }
- }
- Console.WriteLine("{0} - {1}", result[0], result[1]);
- }
- private static int iterateRight()
- {
- if (_matrix[_startRow, _startCol] != '\0')
- {
- return 1;
- }
- for (int i = _startCol; i <= _endCol; i++)
- {
- if (_textIndex >= _text.Length)
- {
- _textIndex = 0;
- }
- _matrix[_startRow, i] = _text[_textIndex];
- _textIndex++;
- }
- _startRow++;
- return 0;
- }
- private static int iterateDown()
- {
- if (_matrix[_startRow, _endCol] != '\0')
- {
- return 1;
- }
- for (int i = _startRow; i <= _endRow; i++)
- {
- if (_textIndex >= _text.Length)
- {
- _textIndex = 0;
- }
- _matrix[i, _endCol] = _text[_textIndex];
- _textIndex++;
- }
- _endCol--;
- return 0;
- }
- private static int iterateLeft()
- {
- if (_matrix[_endRow, _endCol] != '\0')
- {
- return 1;
- }
- for (int i = _endCol; i >= _startCol; i--)
- {
- if (_textIndex >= _text.Length)
- {
- _textIndex = 0;
- }
- _matrix[_endRow, i] = _text[_textIndex];
- _textIndex++;
- }
- _endRow--;
- return 0;
- }
- private static int iterateUp()
- {
- if (_matrix[_startRow, _endCol] != '\0')
- {
- return 1;
- }
- for (int i = _endRow; i >= _startRow; i--)
- {
- if (_textIndex >= _text.Length)
- {
- _textIndex = 0;
- }
- _matrix[i, _startCol] = _text[_textIndex];
- _textIndex++;
- }
- _startCol++;
- return 0;
- }
- private static Boolean isDone()
- {
- return _flag != 0;
- }
- private static void printMatrix()
- {
- for (int i = 0; i < _n; i++)
- {
- for (int b = 0; b < _n; b++)
- {
- Console.Write(_matrix[i, b]);
- }
- }
- Console.Write("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement