Advertisement
osipyonok

Untitled

May 26th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             double x, y, x1, y1, x2, y2, x3, y3, r;
  11.             try
  12.             {
  13.                 for (; ; )
  14.                 {
  15.                     string[] str = Console.ReadLine().Split(new char[] { ' ', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.                     for (int i = 0; i < 6; ++i) str[i] = str[i].Replace('.', ',');
  18.  
  19.                     x1 = double.Parse(str[0]);
  20.                     y1 = double.Parse(str[1]);
  21.                     x2 = double.Parse(str[2]);
  22.                     y2 = double.Parse(str[3]);
  23.                     x3 = double.Parse(str[4]);
  24.                     y3 = double.Parse(str[5]);
  25.  
  26.                     x = ((y3 - y2) / 2 + (x1 - x3) * (x1 + x3) / 2 / (y1 - y3) - (x1 - x2) * (x1 + x2) / 2 / (y1 - y2)) / ((x1 - x3) / (y1 - y3) - (x1 - x2) / (y1 - y2));
  27.                     y = ((x3 - x2) / 2 + (y1 - y3) * (y1 + y3) / 2 / (x1 - x3) - (y1 - y2) * (y1 + y2) / 2 / (x1 - x2)) / ((y1 - y3) / (x1 - x3) - (y1 - y2) / (x1 - x2));
  28.  
  29.                     if (x1 == x2) y = (y1 + y2) / 2;
  30.                     if (x1 == x3) y = (y1 + y3) / 2;
  31.                     if (y1 == y2) x = (x1 + x2) / 2;
  32.                     if (y1 == y3) x = (x1 + x3) / 2;
  33.  
  34.                     r = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
  35.  
  36.                     string ans = "";
  37.  
  38.                     if (Math.Abs(x) != 0) ans += "(";
  39.                     ans += "x";
  40.                     if (Math.Abs(x) != 0)
  41.                     {
  42.                         if (x >= 0) ans += " - ";
  43.                         else ans += " + ";
  44.                         ans += Math.Abs(x).ToString("0.000");
  45.                         ans += ")";
  46.                     }
  47.                     ans += "^2 + ";
  48.                     if (Math.Abs(y) != 0) ans += "(";
  49.                     ans += "y";
  50.                     if (Math.Abs(y) != 0)
  51.                     {
  52.                         if (y >= 0) ans += " - ";
  53.                         else ans += " + ";
  54.                         ans += Math.Abs(y).ToString("0.000");
  55.                         ans += ")";
  56.                     }
  57.                     ans += "^2 = ";
  58.                     ans += r.ToString("0.000");
  59.                     ans += "^2\n";
  60.  
  61.                     ans += "x^2 + y^2 ";
  62.                     if (x != 0)
  63.                     {
  64.                         if (x < 0) ans += "+ ";
  65.                         else ans += "- ";
  66.                         ans += Math.Abs(2 * x).ToString("0.000");
  67.                         ans += "x ";
  68.                     }
  69.                     if (y != 0)
  70.                     {
  71.                         if (y < 0) ans += "+ ";
  72.                         else ans += "- ";
  73.                         ans += Math.Abs(2 * y).ToString("0.000");
  74.                         ans += "y ";
  75.                     }
  76.                     if (x * x + y * y - r * r != 0)
  77.                     {
  78.                         if (x * x + y * y - r * r > 0) ans += "+ ";
  79.                         else ans += "- ";
  80.                         ans += Math.Abs(x * x + y * y - r * r).ToString("0.000");
  81.                         ans += " ";
  82.                     }
  83.                     ans = ans.Replace(',', '.');
  84.                     ans += "= 0\n\n";
  85.                     Console.Write(ans);
  86.  
  87.                 }
  88.             }
  89.             catch { return; }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement