Python 알고리즘 - 알람 시계

Code_Alpacat·2022년 1월 2일
0

Python 알고리즘

목록 보기
7/15

알람 시계

  • 이 문제는 조금 더 까다로운 문제다. 24시간에서 입력받은 시간에서 45분 전을 출력해야한다.
    여기서, 참고해야할 사항은
  1. 입력받은 분이 45분 미만이면, 시간을 -1 한다.
  2. 입력받은 시간이 0 45 미만이면, 23시로 바꿔준다.
x, y = map(int, input().split(" "))

def alram_clock(x, y):
    if(not(x == 0) and y >= 45):
        y -= 45
        print(f"{x} {y}")

    elif(not(x==0) and y<45):
        y += 15
        x -= 1
        print(f"{x} {y}")
    
    elif(x==0 and y >= 45):
        y -= 45
        print(f"{x} {y}")
    
    elif(x==0 and y<45):
        x = 23
        y += 15
        print(f"{x} {y}")
    
    else:
        print("예외")

alram_clock(x, y)

매우 쉬운 문제이지만 파이썬에서 return x, y를 했더니 튜플의 형태로 출력되었다. 그래서 아래처럼 출력도 가능하다.

x, y = map(int, input().split(" "))

def alram_clock(x, y):
    if(not(x == 0) and y >= 45):
        y -= 45
        return x, y

    elif(not(x==0) and y<45):
        y += 15
        x -= 1
        return x, y
    
    elif(x==0 and y >= 45):
        y -= 45
        return x, y
    
    elif(x==0 and y<45):
        x = 23
        y += 15
        return x, y
    
    else:
        print("예외")

result = alram_clock(x, y)

print(f"{result[0]} {result[1]}")
profile
In the future, I'm never gonna regret, cuz I've been trying my best for every single moment.

0개의 댓글