def allocate_books(book_counts, labels):
total_books = sum(book_counts)
if total_books > 4 * 104000:
return "图书数量超过可摆放总量,请重新输入数据"
allocation = {}
current_floor = 4
floor_capacity = {4: 44000, 5: 104000, 6: 104000, 7: 104000, 8: 104000}
remaining_capacity = {4: 44000, 5: 104000, 6: 104000, 7: 104000, 8: 104000}
for i, count in enumerate(book_counts):
while count > remaining_capacity[current_floor]:
allocation[labels[i]] = f"{current_floor}层({labels[i]})"
count -= remaining_capacity[current_floor]
current_floor += 1
remaining_capacity[current_floor] -= count
allocation[labels[i]] = f"{current_floor}层({labels[i]})"
remaining_capacity[current_floor] -= count
return allocation
labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Z']
book_counts = [10000, 20000, 30000, 4000, 5000, 6000, 7000, 8000, 9000, 10000,
11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000,
19000, 20000, 21000, 22000]
allocation = allocate_books(book_counts, labels)
print("图书\t 数量\t 摆放楼层")
for book, location in allocation.items():
print(f"{book}\t {book_counts[labels.index(book)]}\t {location} ")