Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- using System.IO;
- namespace ConsoleApp1
- {
- static class GlobalVar
- {
- static public double R;
- }
- struct SPoint : IComparable<SPoint>
- {
- public int x, y;
- private int countOfPoint;
- static private double R;
- public SPoint(int x, int y)
- {
- this.x = x; this.y = y;
- countOfPoint = 0;
- R = GlobalVar.R;
- }
- static public void calculate(SPoint[] a)
- {
- for (int j = 0; j < a.Length; ++j)
- {
- ref SPoint cur = ref a[j];
- for (int i = 0; i < a.Length; ++i)
- if (Distance(cur, a[i]) <= R)
- cur.countOfPoint++;
- }
- }
- public void Show()
- {
- Console.WriteLine("({0}, {1})", x, y);
- }
- static private double sqr(double a)
- {
- return a * a;
- }
- static public double Distance(SPoint a, SPoint b)
- {
- return Math.Sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
- }
- public int CompareTo(SPoint obj)
- {
- if (this.countOfPoint == obj.countOfPoint)
- {
- return 0;
- }
- else
- {
- if (this.countOfPoint > obj.countOfPoint)
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
- class Program
- {
- static void Print(SPoint[] array) //выводим данные на экран
- {
- foreach (SPoint item in array)
- {
- item.Show();
- }
- }
- static void Main()
- {
- using (StreamReader file = new StreamReader("d:/input.txt"))
- {
- int n = Int32.Parse(file.ReadLine());
- GlobalVar.R = Double.Parse(file.ReadLine());
- SPoint[] a = new SPoint[n];
- for (int i = 0; i < n; ++i)
- {
- int x, y;
- string [] line = file.ReadLine().Split();
- x = int.Parse(line[0]);
- y = int.Parse(line[1]);
- a[i] = new SPoint(x, y);
- }
- SPoint.calculate(a);
- Array.Sort(a); //Вызов стандартной сортировки для класса Array
- Console.WriteLine("Упорядоченные данные: ");
- Print(a);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment