Advertisement
Ochkasty_Dino

Practicum14-I-5

Nov 25th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace ConsoleApp2
  9. {
  10.  
  11.     struct SPoint
  12.     {
  13.         public int x, y;
  14.         public SPoint(int x, int y)
  15.         {
  16.             this.x = x;
  17.             this.y = y;
  18.         }
  19.         public void Show()
  20.         {
  21.             Console.WriteLine("({0}, {1})", x, y);
  22.         }
  23.  
  24.     }
  25.     class Program
  26.     {
  27.         static public SPoint[] Input()
  28.         {
  29.             using (StreamReader fileIn = new StreamReader(@"C:/Users/belousaa/Documents/in1.txt", Encoding.GetEncoding(1251)))
  30.             {
  31.                 int n = int.Parse(fileIn.ReadLine());
  32.                 SPoint[] ar = new SPoint[n]; //описание массива структур
  33.                 for (int i = 0; i < n; i++)
  34.                 {
  35.                     string[] text = fileIn.ReadLine().Split(' ');
  36.                     ar[i] = new SPoint(int.Parse(text[0]), int.Parse(text[1])); //вызов конструктора структуры
  37.                 }
  38.                 return ar; //в качестве результата метод возвращает ссылку на массив структур
  39.             }
  40.  
  41.         }
  42.  
  43.         static public double sras(SPoint[] ar, int i, int j)
  44.         {
  45.             return Math.Sqrt((ar[i].x - ar[j].x) * (ar[i].x - ar[j].x) + (ar[i].y - ar[j].y) * (ar[i].y - ar[j].y));
  46.         }
  47.  
  48.         static void brast(SPoint[] ar)
  49.         {
  50.            
  51.             double mal = 0;
  52.             for (int i = 0; i < ar.Length - 1; i++)
  53.             {
  54.                 for (int j = i + 1; j < ar.Length; j++)
  55.                 {
  56.  
  57.                     if (sras(ar, i, j) > mal)
  58.                     {
  59.                         mal = sras(ar, i, j);
  60.                     }
  61.                 }
  62.  
  63.             }
  64.             for (int i = 0; i < ar.Length - 1; i++)
  65.             {
  66.                 for (int j = i + 1; j < ar.Length; j++)
  67.                 {
  68.  
  69.                     if (sras(ar, i, j) == mal)
  70.                     {
  71.                         ar[i].Show();
  72.                         ar[j].Show();
  73.                         Console.WriteLine("\n");
  74.  
  75.                     }
  76.                 }
  77.  
  78.             }
  79.            
  80.         }
  81.  
  82.         static void Main(string[] args)
  83.         {
  84.             SPoint[] ar = Input();
  85.             brast(ar);
  86.  
  87.         }
  88.     }
  89. }
  90. /*
  91.  
  92. 5
  93. -2 0
  94. -3 0
  95. 11 -11
  96. -11 11
  97. -400 0
  98. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement