Advertisement
Sephinroth

prac 14 ex 1

Dec 7th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.IO;
  7.  
  8. namespace ConsoleApplication2
  9. {
  10.     struct SPoint
  11.     {
  12.         public int x,y;
  13.         //public bool flag = false;
  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.         public double Distance()
  24.         {
  25.             return Math.Sqrt(x*x + y*y);
  26.         }
  27.     }
  28.    
  29.     class Program
  30.     {
  31.         static void Main(string[] args)
  32.         {
  33.             using (StreamReader input = new StreamReader("e:/practice/input.txt", Encoding.GetEncoding(1251)))
  34.             {
  35.                 int n = int.Parse(input.ReadLine());
  36.                 SPoint [] array = new SPoint[n];
  37.                 for (int i = 0; i < n; i++)
  38.                 {
  39.                     string [] x_y = input.ReadLine().Split(' ');
  40.                     array[i].x = int.Parse(x_y[0]);
  41.                     array[i].y = int.Parse(x_y[1]);
  42.                 }
  43.                 using (StreamWriter output = new StreamWriter("e:/practice/output.txt", false))
  44.                 {
  45.                     double min = array[0].Distance();
  46.                     SPoint ans = array[0];
  47.                     for (int i = 1; i < n; i++)
  48.                         if (array[i].Distance() < min)
  49.                             min = array[1].Distance();
  50.                     output.WriteLine("Наименее удаленная точка — ({0}, {1})", ans.x, ans.y);
  51.                 }
  52.             }
  53.                
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement