Advertisement
ar4ebald

Untitled

Jun 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. class Register
  2. {
  3.     private readonly string _path;
  4.  
  5.     public Register(string path)
  6.     {
  7.         this._path = path;
  8.     }
  9.  
  10.     public IEnumerable<Triangle> Triangles
  11.     {
  12.         get
  13.         {
  14.             return File.ReadLines(_path)
  15.                 .Select(i => i.Split(' '))
  16.                 .Select(i => new Triangle()
  17.                 {
  18.                     A = int.Parse(i[0]),
  19.                     B = int.Parse(i[1]),
  20.                     C = int.Parse(i[2]),
  21.                 });
  22.         }
  23.     }
  24. }
  25.  
  26. static class Program2
  27. {
  28.     static bool TryRead(string s, out double x)
  29.     {
  30.         Console.Write("{0}: ", s);
  31.         return double.TryParse(Console.ReadLine(), out x);
  32.     }
  33.  
  34.     static void Print(string msg, IEnumerable<Triangle> triangles)
  35.     {
  36.         Console.WriteLine(msg);
  37.         foreach (var triangle in triangles)
  38.             Console.WriteLine(triangle);
  39.     }
  40.  
  41.     static void Main()
  42.     {
  43.         // Second program
  44.         var register = new Register("Triangles.txt");
  45.         Print("All", register.Triangles);
  46.         Print("1) Sorted by P", register.Triangles.OrderBy(i => i.S));
  47.  
  48.         double threshold;
  49.         if (TryRead("Threshold", out threshold))
  50.         {
  51.             Console.WriteLine("2) S > Threshold");
  52.             foreach (var i in register.Triangles
  53.                 .Where(i => i.S > threshold)
  54.                 .Select(i => new {i.A, i.B, i.C, i.S, i.P}))
  55.             {
  56.                 Console.WriteLine($"A:{i.A}\tB:{i.B}\tC:{i.C}\tP:{i.P}\tS:{i.S:F2}");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement