Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- struct SPoint : IComparable<SPoint>
- {
- public double x;
- public double y;
- public SPoint(double x, double y)
- {
- this.x = x;
- this.y = y;
- }
- public double Distance()
- {
- return Math.Sqrt(this.x * this.x + this.y * this.y);
- }
- public double Distance(SPoint p)
- {
- return Math.Sqrt(Math.Pow(this.x - p.x, 2) + Math.Pow(this.y - p.y, 2));
- }
- public void Show(StreamWriter outFile)
- {
- outFile.WriteLine("{0} {1}", this.x, this.y);
- }
- public int CompareTo(SPoint p)
- {
- if (this.Distance() == p.Distance())
- {
- return 0;
- }
- if (this.Distance() > p.Distance())
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- static void Main(string[] args)
- {
- string inFileName;
- string outFileName;
- using (StreamReader inFile = new StreamReader(inFileName, Encoding.GetEncoding(1251)))
- {
- using (StreamWriter outFile = new StreamWriter(outFileName, false))
- {
- int n = Convert.ToInt32(inFile.ReadLine());
- int index = 0;
- SPoint[] points = new SPoint[n];
- string text;
- double x, y;
- while ((text = inFile.ReadLine()) != null)
- {
- string[] temp = text.Split(' ');
- x = Convert.ToDouble(temp[0]);
- y = Convert.ToDouble(temp[1]);
- SPoint obj = new SPoint(x, y);
- points[index] = obj;
- index++;
- }
- double minSumDistance = 1e18;
- index = -1;
- for (int i = 0; i < points.Length; ++i)
- {
- double sum = 0;
- for (int j = 0; j < points.Length; ++j)
- {
- sum += points[i].Distance(points[j]);
- }
- if (sum < minSumDistance)
- {
- minSumDistance = sum;
- index = i;
- }
- }
- if (index != -1)
- {
- points[index].Show(outFile);
- }
- else
- {
- outFile.WriteLine("Nothing was found. You're gay.");
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment