HR-IPK 2D Array - DS

Jmnote (토론 | 기여)님의 2018년 8월 6일 (월) 21:14 판

1 개요

HR-IPK 2D Array - DS
해커랭크 30 Days of Code
문제 풀이
Arrays e
HR-IPK 2D Array - DS
HR-IPK Arrays: Left Rotation
HR-IPK New Year Chaos
HR-IPK Minimum Swaps 2
HR-IPK Array Manipulation

2 PHP

<?php
function hourglassSum($arr) {
    $cnt = count($arr);
    $max = -100;
    for( $i=1; $i<$cnt-1; $i++) {
        for( $j=1; $j<$cnt-1; $j++ ) {
            $sum = $arr[$i-1][$j-1] + $arr[$i-1][$j] + $arr[$i-1][$j+1]
                + $arr[$i][$j]
                + $arr[$i+1][$j-1] + $arr[$i+1][$j] + $arr[$i+1][$j+1];
            if( $sum > $max ) $max = $sum;
        }
    }
    return $max;
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
$arr == array();
for ($i = 0; $i < 6; $i++) {
    fscanf($stdin, "%[^\n]", $arr_temp);
    $arr[] = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));
}
$result = hourglassSum($arr);
fwrite($fptr, $result . "\n");
fclose($stdin);
fclose($fptr);
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}