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

(새 문서: ==PHP== <source lang='php'> <?php function hourglassSum($arr) { $cnt = count($arr); $max = -100; for( $i=1; $i<$cnt-1; $i++) { for( $j=1; $j<$cnt-1; $j++ ) {...)
 
1번째 줄: 1번째 줄:
==개요==
;<nowiki>HR-IPK 2D Array - DS</nowiki>
* 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 Arrays}}
|}
==PHP==
==PHP==
<source lang='php'>
<source lang='php'>

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 }}