"HR30 Day 11: 2D Arrays"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
9번째 줄: 9번째 줄:


==Java==
==Java==
<source lang='java'>
<syntaxhighlight lang='java'>
import java.io.*;
import java.io.*;
import java.math.*;
import java.math.*;
45번째 줄: 45번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
$stdin = fopen("php://stdin", "r");
$stdin = fopen("php://stdin", "r");
67번째 줄: 67번째 줄:
}
}
echo $max;
echo $max;
</source>
</syntaxhighlight>


==Python==
==Python==
<source lang='python'>
<syntaxhighlight lang='python'>
#!/bin/python3
#!/bin/python3
import math
import math
90번째 줄: 90번째 줄:
             if( sm > mx ): mx = sm
             if( sm > mx ): mx = sm
     print( mx )
     print( mx )
</source>
</syntaxhighlight>

2021년 7월 31일 (토) 10:34 기준 최신판

1 개요[ | ]

Day 11: 2D Arrays
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 Java[ | ]

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {
    private static final Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int[][] arr = new int[6][6];
        for (int i = 0; i < 6; i++) {
            String[] arrRowItems = scanner.nextLine().split(" ");
            scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
            for (int j = 0; j < 6; j++) {
                int arrItem = Integer.parseInt(arrRowItems[j]);
                arr[i][j] = arrItem;
            }
        }
        scanner.close();
        
        int sum;
        int max = -100;
        for(int i=1; i<5; i++) {
            for(int j=1; j<5; 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;
            }
        }
        System.out.println( max );
    }
}

3 PHP[ | ]

<?php
$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));
}
fclose($stdin);
$max = -100;
for($i=1; $i<count($arr)-1; $i++) {
    for($j=1; $j<count($arr[0])-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;
    }
}
echo $max;

4 Python[ | ]

#!/bin/python3
import math
import os
import random
import re
import sys

if __name__ == '__main__':
    arr = []
    for _ in range(6):
        arr.append(list(map(int, input().rstrip().split())))
    mx = -100
    for i in range(1,len(arr)-1):
        for j in range(1,len(arr[0])-1):
            sm = 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( sm > mx ): mx = sm
    print( mx )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}