입력으로 주어진 8자리 날짜를 연, 월, 일 분리
숫자로 받을 것인가
문자열로 받을 것인가
자리수에 따라 날짜 분리를 위해 문자열로 받는다.
출력시 한자리 수의 경우 앞에 0이 붙어야 한다.
하드 코딩을 통해 날짜 성립 조건 확인
날짜 성립 조건인 1~12월의 경우 30일, 31일 분리하여 선언
2월의 경우 28일까지
날짜의 경우 01 ~ 31 리스트 선언, 각 월의 최대 날짜까지 슬라이싱으로 사용
출력시 숫자(테스트케이스 번호)와 문자열(결과)를 출력하기 위해 포맷 형식에 유의할 것
T = int(input())
testcase = []
for i in range(T):
testcase.append(input())
thirty = ['04', '06', '09', '11']
thirty_one = ['01', '03', '05', '07', '08', '10', '12']
days = []
for i in range(1, 32):
day = ''
if i < 10:
day += '0' + str(i)
days.append(day)
else:
day = str(i)
days.append(day)
for i in range(T):
year = testcase[i][:4]
month = testcase[i][4:6]
day = testcase[i][6:8]
result = year+'/'+month+'/'+day
if month not in thirty and month not in thirty_one and month != '02':
result = '-1'
elif month in thirty:
if day not in days[:31]:
result = '-1'
elif month in thirty_one:
if day not in days:
result = '-1'
elif month == '02':
if day not in days[:29]:
result = '-1'
print("#%d %s"%((i+1), result))