111,097
社区成员




double[] arr2=new double[10];
int k=0;
for(int i=0;i<arr.Length;i++)
{
for(int j=i+1;j<arr.Length;j++)
{
if(k==arr2.Length)
{
break;
}
arr2[k]=program.CalDis(arr[i], arr[j]));
k++;
}
}
Console.WriteLine("10点之间的最短距离是"+arr2.Min());
Console.WriteLine("10点之间的最长距离是"+arr2.Max());
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConTest
{
class MyPoint
{
private int x;
private int y;
public int X
{
get
{
return x;
}
}
public int Y
{
get
{
return y;
}
}
public MyPoint(int x, int y)
{
this.x = x;
this.y = y;
}
}
class Program
{
public double CalDis(MyPoint point1, MyPoint point2)
{
return Math.Sqrt(Math.Pow(point1.X-point2.X, 2) + Math.Pow(point1.Y-point2.Y, 2));
}
static void Main(string[] args)
{
Program program = new Program();
Random ran1 = new Random(int.MinValue);
Random ran2 = new Random(int.MaxValue);
MyPoint[] arr = new MyPoint[10];
for(int i=0;i<10;i++)
{
arr[i] = new MyPoint(ran1.Next(), ran2.Next());
}
List<double> list = new List<double>();
for(int i=0;i<arr.Length;i++)
{
for(int j=i+1;j<arr.Length;j++)
{
list.Add(program.CalDis(arr[i], arr[j]));
}
}
Console.WriteLine("10点之间的最短距离是"+list.Min());
Console.WriteLine("10点之间的最长距离是"+list.Max());
Console.Read();
}
}
}