1. 程式人生 > >CCF Python題解(100分)201609-2 火車購票

CCF Python題解(100分)201609-2 火車購票

n = int(input())
seats = [[1] * 5 for i in range(20)]
num = list(map(int, input().split()))


def seat(k):
    if k == 1:
        for i in range(20):
            for j in range(5):
                if seats[i][j]:
                    seats[i][j] = 0
                    return i * 5 + j + 1
    elif k ==
2: for i in range(20): for j in range(4): if seats[i][j] and seats[i][j + 1]: seats[i][j] = 0 seats[i][j + 1] = 0 return i * 5 + j + 1 return None elif k == 3: for i in range(20): for
j in range(3): if seats[i][j] and seats[i][j + 1] and seats[i][j + 2]: seats[i][j] = 0 seats[i][j + 1] = 0 seats[i][j + 2] = 0 return i * 5 + j + 1 return None elif k == 4: for i in range
(20): for j in range(2): if seats[i][j] and seats[i][j + 1] and seats[i][j + 2] and seats[i][j + 3]: seats[i][j] = 0 seats[i][j + 1] = 0 seats[i][j + 2] = 0 seats[i][j + 3] = 0 return i * 5 + j + 1 return None elif k == 5: for i in range(len(seats)): if seats[i] == [1] * 5: seats[i] = [0] * 5 return i * 5 + 1 return None for k in num: first = seat(k) if first: for i in range(first, first + k): print(i, end=" ") else: for j in range(k): print(seat(1), end=" ") print()