fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var minMaxList = new List<Entry>
  10. {
  11. new Entry { Min = 2, Max = 120, FileName = "file1.txt" },
  12. new Entry { Min = 2, Max = 150, FileName = "file2.txt" },
  13. new Entry { Min = 5, Max = 150, FileName = "file3.txt" }
  14. };
  15.  
  16. var minMaxInfo = minMaxList
  17. .Skip(1)
  18. .Aggregate(
  19. new
  20. {
  21. V = new int[]
  22. {
  23. 0, //Index
  24. minMaxList[0].Min, //Min
  25. minMaxList[0].Max //Max
  26. },
  27. MaxIndexes = new List<int> { 0 },
  28. MinIndexes = new List<int> { 0 }
  29. },
  30. (r, t) =>
  31. {
  32. r.V[0]++;
  33.  
  34. if (t.Min < r.V[1])
  35. {
  36. r.V[1] = t.Min;
  37. r.MinIndexes.Clear();
  38. r.MinIndexes.Add(r.V[0]);
  39. }
  40. else if (t.Min == r.V[1])
  41. {
  42. r.MinIndexes.Add(r.V[0]);
  43. }
  44.  
  45. if (t.Max > r.V[2])
  46. {
  47. r.V[2] = t.Max;
  48. r.MaxIndexes.Clear();
  49. r.MaxIndexes.Add(r.V[0]);
  50. }
  51. else if (t.Max == r.V[0])
  52. {
  53. r.MaxIndexes.Add(r.V[0]);
  54. }
  55.  
  56. return r;
  57. });
  58.  
  59. Console.WriteLine("MaxValue: {0}", minMaxInfo.V[2]);
  60. Console.WriteLine(
  61. "MaxFiles: {0}",
  62. string.Join(", ", minMaxInfo.MaxIndexes.Select(i => minMaxList[i].FileName)));
  63. Console.WriteLine("MinValue: {0}", minMaxInfo.V[1]);
  64. Console.WriteLine(
  65. "MinFiles: {0}",
  66. string.Join(", ", minMaxInfo.MinIndexes.Select(i => minMaxList[i].FileName)));
  67. }
  68. }
  69.  
  70. struct Entry
  71. {
  72. public int Min;
  73. public int Max;
  74. public string FileName;
  75. }
Success #stdin #stdout 0.05s 24296KB
stdin
Standard input is empty
stdout
MaxValue: 150
MaxFiles: file2.txt
MinValue: 2
MinFiles: file1.txt, file2.txt