tanya_zheleva

3

Feb 12th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     public sealed class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             double[] firstCoordinates = Console.ReadLine()
  12.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(double.Parse)
  14.                 .ToArray();
  15.             double[] secondCoordinates = Console.ReadLine()
  16.                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  17.                .Select(double.Parse)
  18.                .ToArray();
  19.  
  20.             Circle firstCircle = new Circle(new Point(firstCoordinates[0], firstCoordinates[1]), firstCoordinates[2]);
  21.             Circle secondCircle = new Circle(new Point(secondCoordinates[0], secondCoordinates[1]), secondCoordinates[2]);
  22.             double distance = CalculateDistance(firstCircle, secondCircle);
  23.  
  24.             bool doIntersect = distance <= firstCircle.Radius + secondCircle.Radius;
  25.  
  26.             if (doIntersect)
  27.             {
  28.                 Console.WriteLine("Yes");
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("No");
  33.             }
  34.         }
  35.  
  36.         private static double CalculateDistance(Circle first, Circle second)
  37.         {
  38.             double a = Math.Abs(first.Center.X - second.Center.X);
  39.             double b = Math.Abs(first.Center.Y - second.Center.Y);
  40.             double c = Math.Sqrt(a * a + b * b);
  41.  
  42.             return c;
  43.         }
  44.     }
  45.  
  46.     public sealed class Circle
  47.     {
  48.         public Circle(Point center, double radius)
  49.         {
  50.             this.Center = center;
  51.             this.Radius = radius;
  52.         }
  53.  
  54.         public Point Center { get; private set; }
  55.  
  56.         public double Radius { get; private set; }
  57.     }
  58.  
  59.     public sealed class Point
  60.     {
  61.         public Point(double x, double y)
  62.         {
  63.             this.X = x;
  64.             this.Y = y;
  65.         }
  66.  
  67.         public double X { get; private set; }
  68.  
  69.         public double Y { get; private set; }
  70.     }
  71. }
Add Comment
Please, Sign In to add comment