### Задание №1 - [Миша и негатив](https://acmp.ru/index.asp?main=task&id_task=715) ``` class Program { static void Main() { string[] dimensions = Console.ReadLine().Split(); int n = int.Parse(dimensions[0]); int m = int.Parse(dimensions[1]); string[] originalImage = new string[n]; string[] generatedNegative = new string[n]; for (int i = 0; i < n; i++) { originalImage[i] = Console.ReadLine(); } Console.ReadLine(); for (int i = 0; i < n; i++) { generatedNegative[i] = Console.ReadLine(); } int errorCount = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { char expectedPixel = originalImage[i][j] == 'B' ? 'W' : 'B'; if (generatedNegative[i][j] != expectedPixel) { errorCount++; } } } Console.WriteLine("Колличество ошибок:"); Console.WriteLine(errorCount); } } ``` ### Результат: ``` 2 2 BW BB WW BW Колличество ошибок: 2 ``` ### Задание №2 - [Симпатичный узор](https://acmp.ru/index.asp?main=task&id_task=924) ``` class Program { static void Main() { char[,] tiles = new char[4, 4]; Console.WriteLine("Введите узор плиток (4 строки по 4 символа, 'W' или 'B'):"); for (int i = 0; i < 4; i++) { string line = Console.ReadLine(); while (line.Length != 4 || !IsValidLine(line)) { Console.WriteLine("Ошибка: введите 4 символа 'W' или 'B'. Попробуйте снова:"); line = Console.ReadLine(); } for (int j = 0; j < 4; j++) { tiles[i, j] = line[j]; } } bool isSympathetic = true; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (tiles[i, j] == tiles[i, j + 1] && tiles[i, j] == tiles[i + 1, j] && tiles[i, j] == tiles[i + 1, j + 1]) { isSympathetic = false; break; } } if (!isSympathetic) break; } Console.WriteLine(isSympathetic ? "Yes" : "No"); } static bool IsValidLine(string line) { foreach (char c in line) { if (c != 'W' && c != 'B') { return false; } } return true; } } ``` ### Результат: ``` Введите узор плиток (4 строки по 4 символа, 'W' или 'B'): BBWB BBWB WWBW BBWB NO ``` ### Задание №3 [Морской бой](https://acmp.ru/index.asp?main=task&id_task=493) ``` class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); char[,] field = new char[n, m]; for (int i = 0; i < n; i++) { string row = Console.ReadLine(); for (int j = 0; j < m; j++) { field[i, j] = row[j]; } } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (field[i, j] == '.') { bool canPlace = true; if (i > 0 && field[i - 1, j] == '*') canPlace = false; if (i < n - 1 && field[i + 1, j] == '*') canPlace = false; if (j > 0 && field[i, j - 1] == '*') canPlace = false; if (j < m - 1 && field[i, j + 1] == '*') canPlace = false; if (canPlace) count++; } } } Console.WriteLine("Ответ:"); Console.WriteLine(count); } } ``` ### Результат: ``` 4 3 *** ... ... *** Ответ: 0 ``` ### Задание №4 [Художник](https://acmp.ru/index.asp?main=task&id_task=27) ``` public static void Main(string[] args) { string[] wh = Console.ReadLine().Split(' '); int w = int.Parse(wh[0]); int h = int.Parse(wh[1]); int n = int.Parse(Console.ReadLine()); bool[,] canvas = new bool[w, h]; for (int i = 0; i < n; i++) { string[] rect = Console.ReadLine().Split(' '); int x1 = int.Parse(rect[0]); int y1 = int.Parse(rect[1]); int x2 = int.Parse(rect[2]); int y2 = int.Parse(rect[3]); for (int x = x1; x < x2; x++) { for (int y = y1; y < y2; y++) { canvas[x, y] = true; } } } int unpaintedArea = 0; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (!canvas[x, y]) { unpaintedArea++; } } } Console.WriteLine("Незакрашенная часть холста:"); Console.WriteLine(unpaintedArea); } ``` ### Результат: ``` 5 5 2 1 1 3 3 2 2 4 4 Незакрашенная часть холста 18 ``` ### Задание №5 [Шахматная доска](https://acmp.ru/index.asp?main=task&id_task=265) ``` static void Main() { int N = int.Parse(Console.ReadLine()); HashSet<(int, int)> cutCells = new HashSet<(int, int)>(); for (int i = 0; i < N; i++) { var coords = Console.ReadLine().Split(); int row = int.Parse(coords[0]); int col = int.Parse(coords[1]); cutCells.Add((row, col)); } int perimeter = 0; foreach (var (row, col) in cutCells) { int[] dRow = { -1, 1, 0, 0 }; int[] dCol = { 0, 0, -1, 1 }; for (int i = 0; i < 4; i++) { int neighborRow = row + dRow[i]; int neighborCol = col + dCol[i]; if (!cutCells.Contains((neighborRow, neighborCol))) { perimeter++; } } } Console.WriteLine(perimeter); } ``` ### Результат ``` 1 8 8 4 ```