SWEA

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

가은(JANE) 2024. 11. 16. 21:27

#Problem

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

 

SW Expert Academy

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

swexpertacademy.com

#Think

  • 우선 테스트 케이스가 10으로 고정되어 있는 걸 잊지 마러ㅋ
  • zip에 대해 알게 되었다.
  • for col in zip(*maze): 이러면 세로로 각 값 더할 수 있음
  • for row in maze: 이러면 행 값 더할 수 있음.

#Code

for tc in range(1, 11):
    test_case_number = int(input())  # 테스트 케이스 번호 읽기
    maze = [list(map(int, input().split())) for _ in range(100)]  # 100x100 행렬 입력

    results = []

    # 좌측 내려가는 대각선의 합
    sum_l = 0
    for i in range(100):
        sum_l += maze[i][i]
    results.append(sum_l)

    # 우측 올라가는 대각선의 합
    sum_r = 0
    for i in range(100):
        sum_r += maze[i][99 - i]
    results.append(sum_r)

    # 행의 합
    for row in maze:
        row_sum = sum(row)
        results.append(row_sum)

    # 열의 합
    for col in zip(*maze):
        col_sum = sum(col)
        results.append(col_sum)

    # 최댓값 출력
    max_num = max(results)
    print(f"#{tc} {max_num}")