Advertisement
Guest User

SnakeMoves

a guest
Jan 24th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SnakeMoves
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var matrixDimension = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToArray();
  15.  
  16. int rows = matrixDimension[0];
  17. int cols = matrixDimension[1];
  18.  
  19. var snakeMatrix = new char[rows, cols];
  20.  
  21. string snake = Console.ReadLine();
  22.  
  23. int counter = 0;
  24.  
  25. for (int row = 0; row < snakeMatrix.GetLength(0); row++)
  26. {
  27. if (row % 2 == 0 )
  28. {
  29. for (int col = 0; col < snakeMatrix.GetLength(1); col++)
  30. {
  31. snakeMatrix[row, col] = snake[counter++];
  32.  
  33. if (counter == snake.Length)
  34. {
  35. counter = 0;
  36. }
  37. } // for za koloni
  38. } // if za chetni koloni
  39. else
  40. {
  41. for (int col = snakeMatrix.GetLength(1) - 1; col >= 0; col--)
  42. {
  43. snakeMatrix[row, col] = snake[counter++];
  44.  
  45. if (counter == snake.Length)
  46. {
  47. counter = 0;
  48. }
  49. }// for za koloni
  50. } // else za nechetni koloni
  51. }
  52. for (int row = 0; row < snakeMatrix.GetLength(0); row++)
  53. {
  54. for (int col = 0; col < snakeMatrix.GetLength(1); col++)
  55. {
  56. Console.Write(snakeMatrix[row, col]);
  57.  
  58. }
  59. Console.WriteLine();
  60. }
  61.  
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement