Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Linq;
- using System.Text;
- namespace Snake_Moves
- {
- class SnakeMoves
- {
- static void Main(string[] args)
- {
- int[] inputDimention = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int row = inputDimention[0];
- int col = inputDimention[1];
- char[,] matrix = new char[row, col];
- StringBuilder snake = new StringBuilder(Console.ReadLine());
- if (snake.Length > 0)
- {
- int r = 0;
- int c = 0;
- for (int i = 0; i < (row * col); i++)
- {
- char sh = snake[0];
- snake.Remove(0, 1);
- snake.Append(sh);
- matrix[r, c] = sh;
- if (r % 2 == 0)
- {
- c++;
- }
- else
- {
- c--;
- }
- if (c == col)
- {
- c--;
- r++;
- }
- if (c < 0)
- {
- c++;
- r++;
- }
- }
- }// if (snake.Length > 0
- StringBuilder temp = new StringBuilder();
- snake.Clear();
- for (int r = 0; r < row; r++)
- {
- temp.Clear();
- for (int c = 0; c < col; c++)
- {
- temp.Append($"{matrix[r, c]}");
- }
- snake.AppendLine(temp.ToString());
- }
- Console.WriteLine(snake.ToString());
- }
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement