Advertisement
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
- {
- public double X { get; }
- public double Y { get; }
- 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
- {
- public CustomPoint P1 { get; }
- public CustomPoint P2 { get; }
- public Line(CustomPoint p1 = new CustomPoint(), CustomPoint p2 = new CustomPoint())
- {
- P1 = p1;
- P2 = p2;
- }
- }
- #endregion
- static void Main(string[] args)
- {
- {
- var line1 = GetInputLine();
- var line2 = GetInputLine();
- var longerLine = LongerOfTwoLines(line1, line2);
- PrintLine(longerLine);
- }
- }
- #region Tools
- static CustomPoint GetInputPoint()
- {
- double x = double.Parse(Console.ReadLine());
- double y = double.Parse(Console.ReadLine());
- return new CustomPoint(x, y);
- }
- static Line GetInputLine()
- {
- return new Line(GetInputPoint(), GetInputPoint());
- }
- static Line LongerOfTwoLines(Line line1, Line line2)
- {
- return line1.P1.DistanceToPoint(line1.P2) >= line2.P1.DistanceToPoint(line2.P2) ? line1 : line2;
- }
- static void PrintLine(Line line)
- {
- CustomPoint farFromCenterLinePoint;
- CustomPoint closerToCenterLinePoint = GetCloserToCenterLinePoint(line, out farFromCenterLinePoint);
- Console.Write(closerToCenterLinePoint.ToString());
- Console.WriteLine(farFromCenterLinePoint.ToString());
- }
- static CustomPoint GetCloserToCenterLinePoint(Line line, out CustomPoint farFromCenterLinePoint)
- {
- if (line.P1.IsCloserToCenterThanPoint(line.P2))
- {
- farFromCenterLinePoint = line.P2;
- return line.P1;
- }
- farFromCenterLinePoint = line.P1;
- return line.P2;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement