Created
September 27, 2018 09:20
-
-
Save flymio/01397aab870cd09f0edbe1f1332de575 to your computer and use it in GitHub Desktop.
my new knowledges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Complete the diagonalDifference function below. | |
function diagonalDifference($arr) { | |
$count = count($arr); | |
$d1=0; $d2=0; | |
for($i=0;$i<$count;$i++){ | |
$d1+=$arr[$i][$i]; | |
$d2+=$arr[$i][$count-$i-1]; | |
} | |
return abs($d2-$d1); | |
} | |
$fptr = fopen(getenv("OUTPUT_PATH"), "w"); | |
$stdin = fopen("php://stdin", "r"); | |
fscanf($stdin, "%d\n", $n); | |
$arr = []; | |
for ($i = 0; $i < $n; $i++) { | |
fscanf($stdin, "%[^\n]", $arr_temp); | |
$arr[] = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY)); | |
} | |
$result = diagonalDifference($arr); | |
echo $result; | |
fwrite($fptr, $result . "\n"); | |
fclose($stdin); | |
fclose($fptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. забрать весь файл и по строчкам разложить: $lines = explode(PHP_EOL, file_get_contents('php://stdin')); | |
2. $n = array_shift($lines); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment