본문 바로가기
HackerRank Algorithm

[HackerRank] 13. Drawing Book

by KIha_Jung 2020. 3. 9.

def pageCount(n, p):
    # 처음부터 시작할 때 : 0, 2, 4...
    # 끝에서 시작할 때 : n // 2
    # p가 있는 페이지 : p // 2
    # 거리차를 구해서 min 출력
    last_page = n // 2
    current_page = p // 2
    first_page = 0
    
    if last_page - current_page > current_page - first_page:
        return current_page - first_page
    else:
        return last_page - current_page
      
def main():
    n = int(input())
    p = int(input())
    
    result = pageCount(n, p)
    print(result)
    
if __name__ == '__main__':
    main()

댓글