SW Expert

[SWEA] 1209 [S/W 문제해결 기본] 2일차 - Sum Python

꿀떡최고 2021. 5. 14. 10:05
반응형

[ 문제 ]

 

난이도:  D3

문제 번호:  1209

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13_BWKACUCFAYh&categoryId=AV13_BWKACUCFAYh&categoryType=CODE&problemTitle=1209&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


 

다음 100X100의 2차원 배열이 주어질 때, 각 행의 합, 각 열의 합, 각 대각선의 합 중

최댓값을 구하는 프로그램을 작성하여라.

다음과 같은 5X5 배열에서 최댓값은 29이다.

 

[제약 사항]

총 10개의 테스트 케이스가 주어진다.

배열의 크기는 100X100으로 동일하다.

각 행의 합은 integer 범위를 넘어가지 않는다.

동일한 최댓값이 있을 경우, 하나의 값만 출력한다.

 


 

[ 코드 ]

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
= 10
 
for tc in range(1, T+1):
    li = []
    result = []
    N = int(input())
 
    for i in range(100):
        lis = list(map(int, input().split()))
        li.append(lis)
 
    for i in range(len(li)):
        total1, total2 = 00
        for j in range(100):
            total1 += li[i][j]
            total2 += li[j][i]
        result.append(total1)
        result.append(total2)
 
    for j in range(len(li)):
        total1, total2 = 00
        total1 += li[j][j]
        total2 += li[j][99 - j]
    result.append(total1)
    result.append(total2)
 
 
    max_num = 0
    for number in result:
        if number > max_num:
            max_num = number
 
    print(f'#{tc} {max_num}')
cs
반응형