BOJ - 1111 - IQ Test

Updated:

def solution():
    N = int(input())
    number = list(map(int, input().split()))

    if N == 1:
        print("A")
    elif N == 2:
        if number[0] == number[1]: print(number[0])
        else: print("A")
    else:
        a = 0
        x = number[1] - number[0]
        y = number[2] - number[1]

        if x != 0:
            a = y // x
        b = number[1] - a * number[0]

        for i in range(1, N):
            if number[i] != (number[i-1] * a + b):
                print("B")
                return
        print(number[-1] * a + b)

solution()

https://www.acmicpc.net/problem/1111

Categories:

Updated:

Leave a comment