forked from leocamello/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
65 lines (54 loc) · 1.08 KB
/
main.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
// matrix creation
char **square_map = new char*[n];
for (unsigned int i = 0; i < n; i++)
{
square_map[i] = new char[n];
}
for (unsigned int row = 0; row < n; row++)
{
string entire_row;
cin >> entire_row;
for (unsigned int column = 0; column < n; column++)
{
square_map[column][row] = entire_row[column];
}
}
for (unsigned int r = 1; r < n - 1; r++)
{
for (unsigned int c = 1; c < n - 1; c++)
{
if (square_map[c][r] > square_map[c - 1][r]
&& square_map[c][r] > square_map[c + 1][r]
&& square_map[c][r] > square_map[c][r - 1]
&& square_map[c][r] > square_map[c][r + 1])
{
square_map[c][r] = 'X';
}
}
}
for (unsigned int row = 0; row < n; row++)
{
for (unsigned int column = 0; column < n; column++)
{
cout << square_map[column][row];
}
cout << endl;
}
// matrix deletion
for (unsigned int i = 0; i < n; i++)
{
delete[] square_map[i];
}
delete[] square_map;
return 0;
}