using System.Collections.Generic;
public static void Main()
var shapes = new ShapeParser().ParseShapes(input);
new ShapeWriter(Console.Out).WriteShapes(shapes.Where(x => x.IsValid()).OrderByDescending(x => x.GetArea()));
private System.IO.TextWriter writer;
public ShapeWriter(System.IO.TextWriter writer)
public void WriteShapes(IEnumerable<IShape> shapes)
foreach (var shape in shapes)
writer.Write($"{shape.GetName()} {shape.GetArea()} {Environment.NewLine}");
public IEnumerable<IShape> ParseShapes(string input)
var shapes = new System.Collections.Generic.List<IShape>();
foreach (var shape in input.Split(Environment.NewLine))
var parts = shape.Trim(' ').Split(' ');
Double.TryParse(parts[1], out partOne);
Double.TryParse(parts[2], out partTwo);
switch (parts[0].ToLower())
shapes.Add(new Rectangle(partOne, partTwo));
shapes.Add(new Square(partOne));
shapes.Add(new Circle(partOne));
shapes.Add(new Triangle(partOne, partTwo));
public record Circle(double diameter) : IShape
return Math.PI * Math.Pow((diameter/2), 2);
public record Square(double width) : IShape
return Math.Pow(width, 2);
public record Rectangle(double height, double width) : IShape
return height > 0 && width > 0;
public record Triangle(double width, double height) : IShape
return height * width / 2;
return height > 0 && width > 0;