본문 바로가기
Problem Solving/SWEA

[SWEA|파이썬] 1209. [S/W 문제해결 기본] 2일차 - Sum (D3)

by 청량리 물냉면 2023. 5. 9.
반응형
문제

https://tinyurl.com/2k89refl

 

SW Expert Academy

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

swexpertacademy.com

 

 

🐍파이썬
T = 10
for test_case in range(1, T + 1):
    test_num = int(input())
    arr = [list(map(int, input().split())) for _ in range(100)]
    ans = [0] * 4
    for i in range(100):
        row_sum = 0
        col_sum = 0
        for j in range(100):
            row_sum += arr[i][j]
            col_sum += arr[j][i]
            if i == j:	#대각선(왼->오)
                ans[2] += arr[i][j]
            if i + j == 99:	#대각선(오->왼)
                ans[3] += arr[i][j]
        if ans[0] < row_sum:	#기존 행 값보다 더 큰 값이 들어오면
            ans[0] = row_sum	#값을 변경
        if ans[1] < col_sum:	#기존 열 값보다 더 큰 값이 들어오면
            ans[1] = col_sum	#값을 변경
    print("#{} {}".format(test_case, max(ans)))

 

for test_case in range(1, 11):
    _ = int(input())
    arr = []
    r_hap = 0
    c_hap, c_hap2 = 0, 0
    g_hap, g_hap2 = 0, 0
    for _ in range(100):
        a = list(map(int, input().split()))
        r_hap = max(r_hap, sum(a))  #가로합 최댓값
        arr.append(a)
    for j in range(100):
        c_hap = 0
        for i in range(100):
            c_hap += arr[i][j]  #세로합
            if i == j:	#대각선(왼->오)
                g_hap += arr[i][j]
            if i + j == 99:	#대각선(오->왼)
                g_hap2 += arr[i][j]
        c_hap2 = max(c_hap, c_hap2)	#매번 최대값으로 c_hap2를 갱신
    print("#{} {}".format(test_case, max(r_hap, c_hap2, g_hap, g_hap2)))

 

반응형