Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace App1
- {
- class Program
- {
- public const int LEFT_RIGHT = 1;
- public const int UP_DOWN = 2;
- public const int RIGHT_LEFT = 3;
- public const int DOWN_UP = 4;
- static void Main(string[] args)
- {
- Console.WriteLine("M");
- int m = int.Parse(Console.ReadLine());
- Console.WriteLine("N");
- int n = int.Parse(Console.ReadLine());
- char[,] matrix = new char[n, m];
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine($"eow");
- char[] row = Console.ReadLine().ToCharArray();
- for (int j = 0; j < m; j++) matrix[i, j] = row[j];
- }
- log(matrix, n, m);
- }
- public static void log(char[,] matrix, int n, int m)
- {
- if (n == 1 && m == 1)
- {
- Console.WriteLine(matrix[0, 0]);
- return;
- }
- bool[,] sm = new bool[n, m];
- int countx = 0; int county = 0;
- int position = LEFT_RIGHT;
- string result = "";
- while (!sm[county, countx])
- {
- switch (position)
- {
- case LEFT_RIGHT:
- {
- for (int i = 0; i < m; i++)
- {
- sm[county, countx] = true;
- result += matrix[county, countx];
- countx++;
- }
- countx--; county++; n--; m--;
- break;
- }
- case UP_DOWN:
- {
- for (int i = 0; i < n; i++)
- {
- sm[county, countx] = true;
- result += matrix[county, countx];
- county++;
- }
- county--; countx--;
- break;
- }
- case RIGHT_LEFT:
- {
- for (int i = 0; i < m; i++)
- {
- sm[county, countx] = true;
- result += matrix[county, countx];
- countx--;
- }
- countx++; county--; n--; m--;
- break;
- }
- case DOWN_UP:
- {
- for (int i = 0; i < n; i++)
- {
- sm[county, countx] = true;
- result += matrix[county, countx];
- county--;
- }
- county++; countx++;
- break;
- }
- }
- if (++position > DOWN_UP) position = LEFT_RIGHT;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement