iliya87

01.CoordinatesInTriangle

Mar 26th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2.  
  3. public class Triangle
  4. {
  5.     public static void Main()
  6.     {
  7.         System.Threading.Thread.CurrentThread.CurrentCulture =
  8.             System.Globalization.CultureInfo.InvariantCulture;
  9.  
  10.         int aX = int.Parse(Console.ReadLine());
  11.         int aY = int.Parse(Console.ReadLine());
  12.         int bX = int.Parse(Console.ReadLine());
  13.         int bY = int.Parse(Console.ReadLine());
  14.         int cX = int.Parse(Console.ReadLine());
  15.         int cY = int.Parse(Console.ReadLine());
  16.  
  17.         double ab = Math.Sqrt(
  18.             (bX - aX) * (bX - aX) +
  19.             (bY - aY) * (bY - aY));
  20.  
  21.         double bc = Math.Sqrt(
  22.             (bX - cX) * (bX - cX) +
  23.             (bY - cY) * (bY - cY));
  24.  
  25.         double ac = Math.Sqrt(
  26.             (cX - aX) * (cX - aX) +
  27.             (cY - aY) * (cY - aY));
  28.  
  29.         bool areFormingTriangle =
  30.             (ab + bc > ac && ab + ac > bc && ac + bc > ab);
  31.  
  32.         if (areFormingTriangle == false)
  33.         {
  34.             Console.WriteLine("No");
  35.             Console.WriteLine("{0:F2}", ab);
  36.         }
  37.         else
  38.         {
  39.             Console.WriteLine("Yes");
  40.             double p = (ab + bc + ac) / 2;
  41.             double area = Math.Sqrt(p * (p - ab) * (p - bc) * (p - ac));
  42.             Console.WriteLine("{0:F2}", area);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment