-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSharp.cs
53 lines (50 loc) · 1.38 KB
/
CSharp.cs
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;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Player
{
static void Main(string[] args)
{
string[] inputs = Console.ReadLine().Split(' ');
int width = int.Parse(inputs[0]);
int height = int.Parse(inputs[1]);
char[,] grid = new char[height,width];
for (int i = 0; i < height; i++)
{
string line = Console.ReadLine();
for(int j = 0; j < width; j++){
grid[i,j] = line[j];
}
Console.Error.WriteLine(line);
}
for (int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++){
Console.Write(TransformChar(grid, i, j, height, width));
}
Console.WriteLine("");
}
}
static char TransformChar(char[,] grid, int i, int j, int H, int W){
if (grid[i, j] == '#'){
return '#';
}
int nbPassages = 0;
if(i + 1 <= H-1 && grid[i+1, j] == '0'){
nbPassages++;
}
if(i - 1 >= 0 && grid[i-1, j] == '0'){
nbPassages++;
}
if(j + 1 <= W-1 && grid[i, j+1] == '0'){
nbPassages++;
}
if(j - 1 >= 0 && grid[i, j-1] == '0'){
nbPassages++;
}
return nbPassages.ToString()[0];
}
}