gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Напиши программу на C#: Даны координаты центров n окружностей и их радиусы. Определить…
- User
Напиши программу на C#: Даны координаты центров n окружностей и их радиусы. Определить число пересекающихся окружностей.
- Assistant
using System;
class Program { public static bool CheckIntersection(int x1, int y1, int r1, int x2, int y2, int r2) { int distance = (int)Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
if (distance <= (r1 + r2)) { return true; } else { return false; } } static void Main() { Console.Write("Введите количество окружностей: "); int n = int.Parse(Console.ReadLine()); int[] x = new int[n]; int[] y = new int[n]; int[] r = new int[n]; int count = 0; // Ввод координат центров и радиусов окружностей for (int i = 0; i < n; i++) { Console.WriteLine($"Введите координаты центра {i + 1} окружности (x, y): "); x[i] = int.Parse(Console.ReadLine()); y[i] = int.Parse(Console.ReadLine()); Console.Write("Введите радиус окружности: "); r[i] = int.Parse(Console.ReadLine()); } // Проверка пересечения окружностей for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (CheckIntersection(x[i], y[i], r[i], x[j], y[j], r[j])) { count++; } } } Console.WriteLine($"Число пересекающихся окружностей: {count}"); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.