[SWEA] - 4839. 이진탐색

jjiani·2021년 2월 16일
0

SWEA

목록 보기
12/20

-틀린코드

import sys
sys.stdin = open('sample_input (3).txt', 'r')

def search(target, data):
    start = 0
    end = len(data) -1
    count = 0
    while start <= end:
        mid = (start + end)//2
        count += 1
        if data[mid] == target:
            return count
        elif data[mid] < target:
            start = mid + 1
        else:
            end = mid - 1
    return count

for test_case in range(1, int(input())+1):
    P, A, B = map(int, input().split()) #P는 전체 페이지수
    book = [i for i in range(1, P+1)]
    count_a = search(A, book)
    count_b = search(B, book)
    ans = ''
    if count_a > count_b:
        ans = 'B'
    elif count_b > count_a:
        ans = 'A'
    else:
        ans = '0'
    print('#{} {}'.format(test_case, ans))
profile
¡Bienvenido a mi velog!🐣

0개의 댓글