using System;
using System.Collections.Generic;
using System.Linq;
namespace Queue
{
public class Queue<T>
{
private List<T> _items = new List<T>();
public int Count => _items.Count;
public void Enqueue(T item)
{
if(item == null)
{
throw new ArgumentNullException(nameof(item));
}
_items.Add(item);
}
public T Dequeue()
{
var item = GetItem();
_items.Remove(item);
return item;
}
public T Peek()
{
var item = GetItem();
return item;
}
private T GetItem()
{
var item = _items.FirstOrDefault();
if (item == null)
{
throw new NullReferenceException("Очередь пуста. Нет элементов для получения.");
}
return item;
}
}
}
namespace Queue
{
class Program
{
static void Main(string[] args)
{
// Создаем новую очередь.
var queue = new Queue<int>();
// Добавляем новые элементы в очередь.
queue.Enqueue(1);
queue.Enqueue(7);
queue.Enqueue(42);
queue.Enqueue(69);
queue.Enqueue(-17);
Console.WriteLine($"Очередь содержит {queue.Count} элементов.");
// Получаем элементы с удалением.
var item1 = queue.Dequeue();
Console.WriteLine($"Первый элемент из очереди {item1}.");
var item2 = queue.Dequeue();
Console.WriteLine($"Второй элемент из очереди {item2}.");
// Добавляем новый элемент в очередь.
queue.Enqueue(88);
// Просматриваем элемент без удаления.
var item3 = queue.Peek();
Console.WriteLine($"Обзор элемента без удаления {item3}.");
Console.ReadLine();
}
}
}
1 задача:
import math
a=int(input())
b=int(input())
if(math.fabs(a+b)>20):
print(math.pow(a,2))
else:
b=math.fabs(b)
print(math.sqrt(b))
2 задача:
a=int(input())
if a == 5:
print("Отлично")
elif a == 4:
print("Хорошо")
elif a == 3:
print("Удовлетворительно")
elif a == 2:
print("Плохо")
elif a == 1:
print("Отвратительно")
else:
print("Это не оценка")
3 задача:
x=int(input())
y=int(input())
a=int(input())
b=int(input())
a7 = a%x
b7 = b%y
if(a7>b7):
print("7A")
else:
print("7Б")
4 задача:
import math
print("Введите интервал")
a=int(input())
b=int(input())
while(a<=b):
if a<100:
r=13*math.pow(a,2)
print("X=" + str(a) + " y=" + str(r))
elif a>100:
r=math.pow(a,3)-100
print("X=" + str(a) + " y=" + str(r))
else:
r=30-(a/(a-5))
print("X=" + str(a) + " y=" + str(r))
a=a+1
5 задача:
import math
print("Введите интервал")
a=int(input())
b=int(input())
while(a<=b):
if a<4:
r=3*a-7
print("X=" + str(a) + " y=" + str(r))
else:
r=5*math.pow(a,2)
print("X=" + str(a) + " y=" + str(r))
a=a+1
Объяснение:
public class Test
{
public static void Main()
{
int t, m, l, n, k=0;
Console.Write("M = ");
m = int.Parse(Console.ReadLine());
Console.Write("L = ");
l = int.Parse(Console.ReadLine());
Console.Write("N = ");
n = int.Parse(Console.ReadLine());
Console.Write("Окончание ввода '0'");
do {
Console.Write("Число = ");
t = int.Parse(Console.ReadLine());
if ((t % m == 0)&&(l<=t)&&(t<=n)&&(t != 0)) k++;
}
while (t != 0);
Console.Write("k = {0}", k);
}
}
Пример:
M = 2
L = 10
N = 20
Окончание ввода '0'
Число = 15
Число = 40
Число = 92
Число = 16
Число = 54
Число = 14
Число = 0
k = 2