Advertisement
Daniel_007

05. Snake Moves

Jun 2nd, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Security.Claims;
  4.  
  5. namespace ConsoleApp5
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] inputRowsColums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int rows = inputRowsColums[0];
  13.             int colums = inputRowsColums[1];
  14.             char[,] matrix = new char[rows, colums];
  15.             string input = Console.ReadLine();
  16.             //inputMatrix
  17.             int indexSymbolString = 0;
  18.             for (int row = 0; row < rows; row++)
  19.             {
  20.                 if (row % 2 == 0)
  21.                 {
  22.                     for (int col = 0; col < colums; col++)
  23.                     {
  24.                         if (indexSymbolString >= input.Length)
  25.                         {
  26.                             indexSymbolString = 0;
  27.                         }
  28.  
  29.                         matrix[row, col] = input[indexSymbolString];
  30.                         indexSymbolString++;
  31.                     }
  32.                 }
  33.                 else
  34.                 {
  35.                     for (int col = colums-1; col >= 0; col--)
  36.                     {
  37.                         if (indexSymbolString >= input.Length)
  38.                         {
  39.                             indexSymbolString = 0;
  40.                         }
  41.                         matrix[row, col] = input[indexSymbolString];
  42.                         indexSymbolString++;
  43.                     }
  44.                 }
  45.             }
  46.            //printMatrix
  47.             for (int row = 0; row < rows; row++)
  48.             {
  49.                 for (int col = 0; col < colums; col++)
  50.                 {
  51.                     Console.Write(matrix[row, col]);
  52.                 }
  53.  
  54.                 Console.WriteLine();
  55.             }
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement