Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Test
- {
- static void Main()
- {
- double x1 = double.Parse(Console.ReadLine());
- double y1 = double.Parse(Console.ReadLine());
- double x2 = double.Parse(Console.ReadLine());
- double y2 = double.Parse(Console.ReadLine());
- double x3 = double.Parse(Console.ReadLine());
- double y3 = double.Parse(Console.ReadLine());
- double x4 = double.Parse(Console.ReadLine());
- double y4 = double.Parse(Console.ReadLine());
- PrintTheLongerLine(x1, y1, x2, y2, x3, y3, x4, y4);
- }
- static void PrintTheLongerLine(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
- {
- double firstLineLenght = GetLineLenght(x1, x2, y1, y2);
- double secondLineLenght = GetLineLenght(x3, x4, y3, y4);
- double firstPointDistance = 0;
- double secondPointDistance = 0;
- if (firstLineLenght >= secondLineLenght) // Печатаме точките на 1-вата линия x1, y1, x2, y2
- {
- firstPointDistance = GetDistanceToCenter(x1, y1);
- secondLineLenght = GetDistanceToCenter(x2, y2);
- if (firstPointDistance > secondPointDistance) // вторите точки са по-близо => печатаме тях първо
- {
- Console.WriteLine($"({x2}, {y2})({x1}, {y1})");
- }
- else // първите точки са по-близо => печатаме тях първо
- {
- Console.WriteLine($"({x1}, {y1})({x2}, {y2})");
- }
- }
- else // Печатаме точките на 2-рата линия x3, y3, x4, y4
- {
- firstPointDistance = GetDistanceToCenter(x3, y3);
- secondPointDistance = GetDistanceToCenter(x4, y4);
- if (firstPointDistance > secondPointDistance) // вторите точки са по-близо => печатаме тях първо
- {
- Console.WriteLine($"({x4}, {y4})({x3}, {y3})");
- }
- else // първите точки са по-близо => печатаме тях първо
- {
- Console.WriteLine($"({x3}, {y3})({x4}, {y4})");
- }
- }
- }
- static double GetLineLenght(double x1, double x2, double y1, double y2)
- {
- return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
- }
- static double GetDistanceToCenter(double x, double y)
- {
- return Math.Sqrt(Math.Pow((x - 0), 2) + Math.Pow((y - 0),2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement