-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcavity_map.php
More file actions
27 lines (25 loc) · 807 Bytes
/
Copy pathcavity_map.php
File metadata and controls
27 lines (25 loc) · 807 Bytes
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
<?php
$__fp = fopen("php://stdin", "r");
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
fscanf($__fp, "%d", $_t_cases);
$board = [];
for ($_t_i = 0; $_t_i < $_t_cases; $_t_i++) {
$board[] = str_split(trim(preg_replace('/\s\s+/', ' ', fgets($__fp))));
}
$result = $board;
for ($i = 1; $i < $_t_cases - 1; $i++) {
for ($j = 1; $j < count($board[$i]) - 1; $j++) {
$mid = $board[$i][$j];
$top = $board[$i - 1][$j];
$right = $board[$i][$j + 1];
$bottom = $board[$i + 1][$j];
$left = $board[$i][$j - 1];
if ($mid > $top && $mid > $right && $mid > $bottom && $mid > $left) {
$result[$i][$j] = "x";
}
}
}
foreach ($result as $outout){
echo implode("", $outout)."\n";
}
?>