using System;
using System.Numerics;
class StringQueue
{
private string[] items;
private int front, rear, count, capacity;
public StringQueue(int cap = 10)
{
try { items = new string[capacity = cap]; }
catch { throw new Exception("StringQueue: Нет памяти"); }
}
public void Enqueue(string item)
{
if (count == capacity) throw new Exception("StringQueue: Переполнение");
items[(rear = (rear + 1) % capacity)] = item;
count++;
}
public string Dequeue()
{
if (count == 0) throw new Exception("StringQueue: Пусто");
string item = items[front];
front = (front + 1) % capacity;
count--;
return item;
}
}
class Program
{
static double Calc(double r1, double r2, Complex r3)
{
if (Math.Abs(r2) < 1e-15) throw new DivideByZeroException();
if (Math.Abs(r2) < 1e-10) throw new Exception("Потеря разряда");
return Math.Sin(r1) * Math.PI / r2 - r3.Real;
}
static void Main()
{
// Задание 1
try
{
Console.Write("Возраст: ");
int age = int.Parse(Console.ReadLine());
if (age < 0) throw new Exception("Отрицательный возраст");
Console.Write("Год рождения: ");
int year = int.Parse(Console.ReadLine());
if (year > DateTime.Now.Year) throw new Exception("Год больше текущего");
}
catch (Exception ex) { Console.WriteLine($"Ошибка: {ex.Message}"); }
// Задание 2
while (true)
{
try
{
Console.Write("R1: ");
double r1 = double.Parse(Console.ReadLine());
Console.Write("R2: ");
double r2 = double.Parse(Console.ReadLine());
Console.Write("R3 (действ): ");
double r3r = double.Parse(Console.ReadLine());
Console.Write("R3 (мним): ");
double r3i = double.Parse(Console.ReadLine());
Console.WriteLine($"Результат: {Calc(r1, r2, new Complex(r3r, r3i))}");
}
catch (Exception ex) { Console.WriteLine($"Ошибка: {ex.Message}"); }
}
// Задание 3
var q = new StringQueue(3);
q.Enqueue("1"); q.Enqueue("2"); q.Enqueue("3");
Console.WriteLine(q.Dequeue());
}
}