본문 바로가기
coding 📟/coding test ⌨️

[Softeer] 근무 시간

by 고돌한 데이터 사이언스 2023. 8. 20.
반응형

🧑🏻‍💻 me

import sys

# 한 직원에 대한 5일간 근태 리스트 생성
def workmin(s,e,opt=None):

    # 시간 단위 비교
    if opt == 'h':
        res_m = abs(e-s)*60
    else:
    # 분 단위 비교
        if e > s:
            res_m = abs(e-s)
        else:
            res_m = e-s
    
    return res_m 
              

if __name__ == "__main__":

    # 최종 총 근무시간
    total_min = 0
    
    # input 생성
    for _ in range(5):
        org_s, org_e = map(str,input().split())
        s_time, s_min = map(int,org_s.split(':'))
        e_time, e_min = map(int,org_e.split(':'))

        # 시간 케이스 처리
        res_h = workmin(opt='h', s=s_time, e=e_time)

        # 분 케이스 처리
        res_m = workmin(s=s_min, e=e_min)

        total_min += res_h + res_m


    print(total_min)

🧑🏻‍💻 reference

import sys

total = 0
for i in range(5):
    start, end = sys.stdin.readline().split(" ")
    start_h, start_m = map(int, start.split(":"))
    end_h, end_m = map(int, end.split(":"))

    if end_m >= start_m:
        total += (end_h - start_h) * 60 + end_m - start_m
    else:
        total += (end_h - start_h - 1) * 60 + end_m + 60 - start_m

print(total)
반응형

'coding 📟 > coding test ⌨️' 카테고리의 다른 글

[Softeer] 8단 변속기  (0) 2023.08.21
[Softeer] 금고털이  (0) 2023.08.21
[Softeer] A+B  (0) 2023.08.20

댓글