Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ExamPreparation
- {
- public sealed class Startu
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<Point> points = new List<Point>();
- for (int i = 0; i < n; i++)
- {
- double[] pointTokens = Console.ReadLine()
- .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(double.Parse)
- .ToArray();
- Point point = new Point(pointTokens[0], pointTokens[1]);
- points.Add(point);
- }
- double minDistance = double.MaxValue;
- Point minFirstPoint = null;
- Point minSecondPoint = null;
- for (int i = 0; i < points.Count; i++)
- {
- Point firstPoint = points[i];
- for (int j = i + 1; j < points.Count; j++)
- {
- Point secondPoint = points[j];
- double distance = firstPoint.CalculateDistance(secondPoint);
- if (distance < minDistance)
- {
- minDistance = distance;
- minFirstPoint = firstPoint;
- minSecondPoint = secondPoint;
- }
- }
- }
- Console.WriteLine($"{minDistance:F3}");
- Console.WriteLine(minFirstPoint);
- Console.WriteLine(minSecondPoint);
- }
- }
- public sealed class Point
- {
- public Point(double x, double y)
- {
- this.X = x;
- this.Y = y;
- }
- public double X { get; private set; }
- public double Y { get; private set; }
- public double CalculateDistance(Point point)
- {
- double a = Math.Abs(this.X - point.X);
- double b = Math.Abs(this.Y - point.Y);
- double c = Math.Sqrt(a * a + b * b);
- return c;
- }
- public override string ToString()
- {
- return $"({this.X}, {this.Y})";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement