Advertisement
cap7ainjack

Snake_Matrix

Sep 20th, 2015
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2_0_Snake_matrix
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. int m = int.Parse(Console.ReadLine());
  15.  
  16. int[,] matrix = new int[n,m];
  17. int counter = 1;
  18. int rowCount = 0;
  19.  
  20. for (int row = 0; row < matrix.GetLength(0); row++)
  21. {
  22. if (rowCount == 0)
  23. {
  24. for (int col = 0; col < matrix.GetLength(1); col++)
  25. {
  26.  
  27. matrix[row, col] = counter;
  28. counter++;
  29. rowCount++;
  30. }
  31.  
  32. }
  33.  
  34. row++;
  35. if (rowCount != 0 && row < matrix.GetLength(0))
  36. {
  37.  
  38. for (int col = matrix.GetLength(1)-1; col >= 0; col--)
  39. {
  40. matrix[row, col] = counter;
  41. counter++;
  42.  
  43. }
  44.  
  45. rowCount = 0;
  46. }
  47.  
  48.  
  49. }
  50.  
  51.  
  52. // print the result
  53.  
  54. // Print the result matrix
  55. for (int row = 0; row < matrix.GetLength(0); row++)
  56. {
  57. for (int col = 0; col < matrix.GetLength(1); col++)
  58. {
  59. Console.Write("{0} ", matrix[row, col]);
  60. }
  61.  
  62. Console.WriteLine();
  63. }
  64.  
  65. Console.WriteLine();
  66.  
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement