fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. public class Test
  7. {
  8. private static readonly int[][] matrix = new int[6][];
  9.  
  10. static Test()
  11. {
  12. matrix[0] = new int[] { 1, 2, 3, 4, 5, 6 };
  13. matrix[1] = new int[] { 7, 8, 9, 10, 11, 12 };
  14. matrix[2] = new int[] { 13, 14, 15, 16, 17, 18 };
  15. matrix[3] = new int[] { 19, 20, 21, 22, 23, 24 };
  16. matrix[4] = new int[] { 25, 26, 27, 28, 29, 30 };
  17. matrix[5] = new int[] { 31, 32, 33, 34, 35, 36 };
  18. }
  19.  
  20. public static void Main()
  21. {
  22. var hours = Enumerable.Range(00, 24).Select(i => i.ToString("D2"));
  23. int num = 15;
  24. var matches = matrix
  25. .Select((arr, index) => new { arr, xPos = index + 1 })
  26. .Where(x => x.arr.Contains(num))
  27. .Select(x => new
  28. {
  29. X = x.xPos,
  30. Y = (x.arr.Select((n, i) => new { n, i })
  31. .First(xy => xy.n == num).i) + 1
  32. });
  33. if (matches.Any())
  34. {
  35. var firstMatch = matches.First();
  36. int x = firstMatch.X;
  37. int y = firstMatch.Y;
  38. Console.Write("X:{0} Y:{1}", x,y);
  39. }
  40. else
  41. Console.Write("Value not found in matrix");
  42. }
  43. }
Success #stdin #stdout 0.04s 37136KB
stdin
Standard input is empty
stdout
X:3 Y:3