Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace LongerLine
- {
- class Program
- {
- #region Helper Classes
- //
- // Summary:
- // Represents a CustomPoint that has Point.X and Point.Y
- // values set to zero.
- public struct CustomPoint
- {
- #region Fields
- public double X { get; }
- public double Y { get; }
- #endregion
- #region Static methods
- public static CustomPoint GetInputPoint()
- {
- double x = double.Parse(Console.ReadLine());
- double y = double.Parse(Console.ReadLine());
- return new CustomPoint(x, y);
- }
- #endregion
- public CustomPoint(double x = 0, double y = 0)
- {
- X = x;
- Y = y;
- }
- public double DistanceToPoint(CustomPoint distantPoint)
- {
- double xDiff = distantPoint.X - X;
- double yDiff = distantPoint.Y - Y;
- return Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
- }
- public bool IsCloserToCenterThanPoint(CustomPoint otherPoint)
- {
- return this.DistanceToPoint(new CustomPoint()) <= otherPoint.DistanceToPoint(new CustomPoint());
- }
- public override string ToString()
- {
- return $"({this.X}, {this.Y})";
- }
- }
- // Summary:
- // Represents a pair of CustomPoint that defines a line
- // in a two-dimensional plane.
- public struct Line
- {
- #region Fields
- public CustomPoint P1 { get; }
- public CustomPoint P2 { get; }
- #endregion
- #region Static methods
- public static Line GetInputLine()
- {
- return new Line(CustomPoint.GetInputPoint(), CustomPoint.GetInputPoint());
- }
- public static Line GetTheLongerOfTwoLines(Line line1, Line line2)
- {
- return line1.IsLongerThanLine(line2) ? line1 : line2;
- }
- #endregion
- public Line(CustomPoint p1 = new CustomPoint(), CustomPoint p2 = new CustomPoint())
- {
- P1 = p1;
- P2 = p2;
- }
- public double LineLength
- {
- get
- {
- return this.P1.DistanceToPoint(this.P2);
- }
- }
- public bool IsLongerThanLine(Line otherLine)
- {
- return this.LineLength >= otherLine.LineLength;
- }
- public void GetCloseAndFarFromCenterPoints(out CustomPoint closeToCenterPoint, out CustomPoint farFromCenterPoint)
- {
- if (this.P1.IsCloserToCenterThanPoint(this.P2))
- {
- closeToCenterPoint = this.P1;
- farFromCenterPoint = this.P2;
- }
- else
- {
- closeToCenterPoint = this.P2;
- farFromCenterPoint = this.P1;
- }
- }
- public void Print()
- {
- CustomPoint farFromCenterLinePoint;
- CustomPoint closerToCenterLinePoint;
- this.GetCloseAndFarFromCenterPoints(out closerToCenterLinePoint, out farFromCenterLinePoint);
- Console.Write(closerToCenterLinePoint.ToString());
- Console.WriteLine(farFromCenterLinePoint.ToString());
- }
- }
- #endregion
- static void Main(string[] args)
- {
- {
- var line1 = Line.GetInputLine();
- var line2 = Line.GetInputLine();
- var longerLine = Line.GetTheLongerOfTwoLines(line1, line2);
- longerLine.Print();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment