"HR-IPK 2D Array - DS"의 두 판 사이의 차이

3번째 줄: 3번째 줄:
* https://www.hackerrank.com/challenges/2d-array/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays
* https://www.hackerrank.com/challenges/2d-array/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays


{{HR30 헤더}}
{{HR-IPK 헤더}}
{{HR-IPK Arrays}}
{{HR-IPK Arrays}}
|}
|}

2018년 8월 6일 (월) 21:16 판

1 개요

HR-IPK 2D Array - DS
해커랭크 면접준비키트
문제 C C++ C# Go Java node.js Perl PHP Python Ruby
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 }}