-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSolution.cs
More file actions
53 lines (44 loc) · 1.5 KB
/
Solution.cs
File metadata and controls
53 lines (44 loc) · 1.5 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
42
43
44
45
46
47
48
49
50
51
52
53
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
// Complete the cavityMap function below.
static string[] cavityMap(string[] grid) {
for(var i = 1; i<grid.Length-1; i++) {
for(var j = 1; j<grid[i].Length-1; j++) {
var c = grid[i][j];
if(c > grid[i][j+1] &&
c > grid[i][j-1] &&
c > grid[i+1][j] &&
c > grid[i-1][j]) {
grid[i] = $"{grid[i].Substring(0, j)}X{grid[i].Substring(j+1)}";
j++; //we know that the next cell was smaller than the current one
}
}
}
return grid;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int n = Convert.ToInt32(Console.ReadLine());
string[] grid = new string [n];
for (int i = 0; i < n; i++) {
string gridItem = Console.ReadLine();
grid[i] = gridItem;
}
string[] result = cavityMap(grid);
textWriter.WriteLine(string.Join("\n", result));
textWriter.Flush();
textWriter.Close();
}
}