Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Register
- {
- private readonly string _path;
- public Register(string path)
- {
- this._path = path;
- }
- public IEnumerable<Triangle> Triangles
- {
- get
- {
- return File.ReadLines(_path)
- .Select(i => i.Split(' '))
- .Select(i => new Triangle()
- {
- A = int.Parse(i[0]),
- B = int.Parse(i[1]),
- C = int.Parse(i[2]),
- });
- }
- }
- }
- static class Program2
- {
- static bool TryRead(string s, out double x)
- {
- Console.Write("{0}: ", s);
- return double.TryParse(Console.ReadLine(), out x);
- }
- static void Print(string msg, IEnumerable<Triangle> triangles)
- {
- Console.WriteLine(msg);
- foreach (var triangle in triangles)
- Console.WriteLine(triangle);
- }
- static void Main()
- {
- // Second program
- var register = new Register("Triangles.txt");
- Print("All", register.Triangles);
- Print("1) Sorted by P", register.Triangles.OrderBy(i => i.S));
- double threshold;
- if (TryRead("Threshold", out threshold))
- {
- Console.WriteLine("2) S > Threshold");
- foreach (var i in register.Triangles
- .Where(i => i.S > threshold)
- .Select(i => new {i.A, i.B, i.C, i.S, i.P}))
- {
- Console.WriteLine($"A:{i.A}\tB:{i.B}\tC:{i.C}\tP:{i.P}\tS:{i.S:F2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement