Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- namespace Example
- {
- struct Spoint
- {
- public int x, y, z;
- public static Spoint Get(string points)
- {
- string[] s = points.Split();
- Spoint cur = new Spoint();
- cur.x = Int32.Parse(s[0]);
- cur.y = Int32.Parse(s[1]);
- cur.z = Int32.Parse(s[2]);
- return cur;
- }
- static int sqr(int x)
- {
- return x * x;
- }
- public static double Range(Spoint a, Spoint b)
- {
- return Math.Sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z));
- }
- public override string ToString()
- {
- return x.ToString() + " " + y.ToString() + " " + z.ToString();
- }
- }
- class Program
- {
- static (Spoint, Spoint) Solve(Spoint[] p)
- {
- int fs, sc;
- fs = sc = 0;
- double ans = Double.MaxValue;
- for (int i = 0; i < p.Length; i++)
- {
- for (int j = 0; j < p.Length; j++)
- {
- if (i == j)
- continue;
- double cur = Spoint.Range(p[i], p[j]);
- if (cur < ans)
- {
- ans = cur;
- fs = i;
- sc = j;
- }
- }
- }
- return (p[fs], p[sc]);
- }
- static void Main()
- {
- string[] inpLine = null;
- using (StreamReader inFile = new StreamReader("D:/input.txt"))
- {
- inpLine = inFile.ReadToEnd().Split('\n');
- }
- Spoint[] points = new Spoint[inpLine.Length];
- for (int i = 0; i < points.Length; i++)
- {
- points[i] = Spoint.Get(inpLine[i]);
- }
- var ans = Solve(points);
- Console.WriteLine(ans.Item1);
- Console.WriteLine(ans.Item2);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment