[SW Expert Academy, SWEA 2056] 연월일 달력 (python)
Problem Solving/SWEA

[SW Expert Academy, SWEA 2056] 연월일 달력 (python)

728x90

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

 

SW Expert Academy

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

swexpertacademy.com


※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다.

728x90

T = int(input())

for test_case in range(1, T + 1):
    date = input()
    y = date[:4]
    m = date[4:6]
    d = date[6:]

    # month가 1~12이 아니라면 -1 출력 후 다음 case로
    if (not(1 <= int(m) <= 12)):
        print("#{} -1".format(test_case))
        continue

    # 1, 3, 5, 7, 8, 10, 12월일때
    if (int(m) in [1, 3, 5, 7, 8, 10, 12]):
        # day가 1~31이 아니라면 -1 출력 후 다음 case로
        if (not(1 <= int(d) <= 31)):
            print("#{} -1".format(test_case))
            continue
    # 2월일때
    elif (int(m) == 2):
        # day가 1~28이 아니라면 -1 출력 후 다음 case로
        if (not(1 <= int(d) <= 28)):
            print("#{} -1".format(test_case))
            continue
    # 4, 6, 9, 11월일때
    else:
         # day가 1~30이 아니라면 -1 출력 후 다음 case로
        if (not(1 <= int(d) <= 30)):
            print("#{} -1".format(test_case))
            continue

    print("#{} {}/{}/{}".format(test_case, y, m, d))
728x90