Advertisement
Andreschka

Practic 14.1

Dec 7th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. namespace Example
  6. {
  7.  
  8.     struct Spoint
  9.     {
  10.         public int x, y;
  11.  
  12.         public static Spoint Get(string points)
  13.         {
  14.             string[] s = points.Split();
  15.             Spoint cur = new Spoint();
  16.             cur.x = Int32.Parse(s[0]);
  17.             cur.y = Int32.Parse(s[1]);
  18.             return cur;
  19.         }
  20.         static int sqr(int x)
  21.         {
  22.             return x * x;
  23.         }
  24.  
  25.         public static double Range(Spoint a, Spoint b)
  26.         {
  27.             return Math.Sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
  28.         }
  29.  
  30.         public override string ToString()
  31.         {
  32.             return x.ToString() + " " + y.ToString();
  33.         }
  34.  
  35.     }
  36.  
  37.  
  38.     class Program
  39.     {
  40.  
  41.         static (Spoint, Spoint) Solve(Spoint[] p)
  42.         {
  43.             int first, second;
  44.             first = second = 0;
  45.             double max = 0;
  46.             double sum = 0;
  47.             for (int i = 0; i < p.Length; i++)
  48.             {
  49.                 for (int j = 0; j < p.Length; j++)
  50.                 {
  51.                     if (i == j)
  52.                         continue;
  53.                     double cur = Spoint.Range(p[i], p[j]);
  54.                     sum += cur;
  55.                 }
  56.                 Console.WriteLine(sum);
  57.                 if (sum > max)
  58.                 {
  59.                     max = sum;
  60.                     first = i;
  61.                 }
  62.                 sum = 0;
  63.             }
  64.             return (p[first], p[second]);
  65.         }
  66.  
  67.         static void Main()
  68.         {
  69.             string[] inpLine = null;
  70.             using (StreamReader inFile = new StreamReader("C:/Users/Андрей/Desktop/input.txt"))
  71.             {
  72.                 inpLine = inFile.ReadToEnd().Split('\n');
  73.             }
  74.             Spoint[] points = new Spoint[inpLine.Length];
  75.             for (int i = 0; i < points.Length; i++)
  76.             {
  77.                 points[i] = Spoint.Get(inpLine[i]);
  78.             }
  79.             var max = Solve(points);
  80.             Console.WriteLine(max.Item1);
  81.             Console.ReadKey();
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement