-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (35 loc) · 1.37 KB
/
Program.cs
File metadata and controls
41 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
namespace Cavity_Map {
class Program {
public static char[, ] CavityMap(int length, char[, ] cavities) {
for (int row = 1; row < length - 1; row++) {
for (int col = 1; col < length - 1; col++) {
if ((cavities[row - 1, col] < cavities[row, col]) &&
(cavities[row, col + 1] < cavities[row, col]) &&
(cavities[row + 1, col] < cavities[row, col]) &&
(cavities[row, col - 1] < cavities[row, col])) {
cavities[row, col] = 'X';
}
}
}
return cavities;
}
static void Main(string[] args) {
int length = Convert.ToInt32(Console.ReadLine().Trim());
char[, ] cavities = new char[length, length];
for (int i = 0; i < length; i++) {
char[] row = Console.ReadLine().ToCharArray();
for (int j = 0; j < length; j++) {
cavities[i, j] = row[j];
}
}
char[, ] cavityMap = CavityMap(length, cavities);
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
Console.Write(cavityMap[i, j]);
}
Console.WriteLine();
}
}
}
}