Advertisement
Guest User

Snake Moves

a guest
Oct 1st, 2019
1,566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Snake_Moves
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] nums = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  13. int r = nums[0];
  14. int c = nums[1];
  15. char[,] matrix = new char[r, c];
  16. string snake = Console.ReadLine();
  17. int counter = 0;
  18. var myQue = new Queue<char>();
  19.  
  20. int capacity = r * c;
  21.  
  22. for (int i = 0; i < snake.Length; i++)
  23. {
  24. myQue.Enqueue(snake[i]);
  25. counter++;
  26.  
  27. if (counter == capacity)
  28. {
  29. break;
  30. }
  31. if (i == snake.Length - 1)
  32. {
  33. i = -1;
  34. }
  35. }
  36.  
  37. for (int j = 0; j < r; j++)
  38. {
  39. if (j%2 == 0)
  40. {
  41. for (int i = 0; i < c; i++)
  42. {
  43. matrix[j, i] = myQue.Dequeue();
  44. }
  45. }
  46. else if (j%2 != 0)
  47. {
  48. for (int k = c-1; k > -1 ; k--)
  49. {
  50. matrix[j, k] = myQue.Dequeue();
  51. }
  52. }
  53.  
  54. }
  55.  
  56. for (int row = 0; row < matrix.GetLength(0); row++)
  57. {
  58. for (int col = 0; col < matrix.GetLength(1); col++)
  59. {
  60. Console.Write("{0}", matrix[row, col]);
  61. }
  62.  
  63. Console.WriteLine();
  64. }
  65.  
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement