Загрузка данных
1 задание
using System;
class Program
{
static void Main()
{
Console.Write("Введите N: ");
int n = int.Parse(Console.ReadLine());
int[,] a = new int[n, n];
Console.WriteLine("Введите элементы матрицы:");
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i, j] = int.Parse(Console.ReadLine());
int count = 0;
int maxLocalMin = int.MinValue;
bool found = false;
int[] dx = { -1, -1, -1, 0, 0, 1, 1, 1 };
int[] dy = { -1, 0, 1, -1, 1, -1, 0, 1 };
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
bool isLocalMin = true;
for (int k = 0; k < 8; k++)
{
int ni = i + dx[k];
int nj = j + dy[k];
if (ni >= 0 && ni < n && nj >= 0 && nj < n)
{
if (a[i, j] >= a[ni, nj])
{
isLocalMin = false;
break;
}
}
}
if (isLocalMin)
{
count++;
found = true;
if (a[i, j] > maxLocalMin)
maxLocalMin = a[i, j];
}
}
}
Console.WriteLine("Количество локальных минимумов: " + count);
if (found)
Console.WriteLine("Максимум среди локальных минимумов: " + maxLocalMin);
else
Console.WriteLine("Локальных минимумов нет.");
}
}
2 задание
using System;
class Program
{
struct Person
{
public string Surname;
public string Name;
public string Patronymic;
public string EyeColor;
public int Height;
}
static void Main()
{
string text = "This is a test string with a and t letters";
int countA = 0;
int countT = 0;
foreach (char ch in text.ToLower())
{
if (ch == 'a')
countA++;
if (ch == 't')
countT++;
}
Console.WriteLine("Количество букв a: " + countA);
Console.WriteLine("Количество букв t: " + countT);
if (countA == countT)
{
Console.WriteLine("Количество букв a и t одинаковое.");
return;
}
Person[] people = new Person[3];
if (countA > countT)
Console.WriteLine("Введите данные о 3 девушках:");
else
Console.WriteLine("Введите данные о 3 парнях:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine("\nЧеловек " + (i + 1));
Console.Write("Фамилия: ");
people[i].Surname = Console.ReadLine();
Console.Write("Имя: ");
people[i].Name = Console.ReadLine();
Console.Write("Отчество: ");
people[i].Patronymic = Console.ReadLine();
Console.Write("Цвет глаз: ");
people[i].EyeColor = Console.ReadLine();
Console.Write("Рост: ");
people[i].Height = int.Parse(Console.ReadLine());
}
Console.WriteLine("\nСписок:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(
$"{i + 1}. {people[i].Surname} {people[i].Name} {people[i].Patronymic}, " +
$"цвет глаз: {people[i].EyeColor}, рост: {people[i].Height} см"
);
}
}
}