Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace ConsoleApp1
- {
- struct SPoint : IComparable<SPoint> // описание структуры точки в 3-мерном пр-ве
- {
- public int x, y, z; // поля-данные: координаты точки (x, y, z)
- public SPoint(int x, int y, int z) // конструктор
- {
- this.x = x;
- this.y = y;
- this.z = z;
- }
- public void Show() // вывод данных о точке на экран
- {
- Console.WriteLine("({0}, {1}, {2})\t\t{3:f2}", x, y, z, Distance());
- }
- public double Distance() // расстояние от начала координат до точки
- {
- return Math.Sqrt(x * x + y * y + z * z);
- }
- public int CompareTo(SPoint obj)
- {
- return Distance().CompareTo(obj.Distance());
- }
- }
- class Program
- {
- static void Print(SPoint[] points) // Выводим данные о точках в виде таблицы
- {
- Console.WriteLine("{0, -24}{1, -30}", "Координаты точки", "Расстояние от начала координат");
- foreach (SPoint p in points) p.Show();
- }
- static SPoint[] Input(string fileName) // Читаем данные из файла
- {
- using (StreamReader file = new StreamReader(fileName))
- {
- int n = int.Parse(file.ReadLine());
- SPoint[] points = new SPoint[n];
- for (int i = 0; i < n; ++i)
- {
- string[] coordinates = file.ReadLine().Split(' ');
- points[i] = new SPoint(int.Parse(coordinates[0]),
- int.Parse(coordinates[1]),
- int.Parse(coordinates[2]));
- }
- return points;
- }
- }
- static void Main()
- {
- SPoint[] points = Input("C:/Users/Acer/Desktop/СиАКОД/Задание 14/input1.txt");
- Print(points);
- SPoint ans = points[0]; // точка-ответ на задачу
- foreach (SPoint p in points)
- if (ans.CompareTo(p) < 0) ans = p;
- Console.WriteLine("\nНаиболее удаленная точка:");
- ans.Show();
- }
- };
- }
- /* input1.txt
- 10
- 60 14 -8
- -89 -1 65
- -32 -27 24
- 59 87 -55
- 98 -39 2
- -44 -24 -70
- 41 -3 -12
- 17 -69 -61
- 20 36 -80
- 97 27 -53
- */
Add Comment
Please, Sign In to add comment