4. Office Chairs (Lists Advanced)
Здравейте,
на задача 4 от Lists Advanced джъдж ми дава 80/100 и следното обяснение:
The process executing your submission for this test may not have received the output successfully. Please try to submit again the same solution. If the result does not change, then search the error in the submission itself.
Опитах да събмитна наново, но без успех. Това е кодът ми:
n = int(input())
count_free_seats = 0
needed_chairs = 0
number_of_room = 1
for i in range(0, n):
chairs, people = input().split()
if len(chairs) > int(people):
free_seats = len(chairs) - int(people)
count_free_seats += free_seats
elif len(chairs) < int(people):
needed_chairs = abs(len(chairs) - int(people))
count_free_seats -= needed_chairs
print(f"{needed_chairs} more chairs needed in room {number_of_room}")
number_of_room += 1
if count_free_seats > 0:
print(f"Game On, {count_free_seats} free chairs left")
Благодаря!
Ето и моето решение с булеви променливи. number_of_rooms = int(input()) taken_places = "" number_of_people = 0 number_of_free_chairs = 0 all_seats_are_taken = True for i in range(1, number_of_rooms + 1): chairs = input().split() taken_places = (chairs[0]) number_of_people = (int(chairs[1])) if len(taken_places) == number_of_people: continue elif len(taken_places) > number_of_people: number_of_free_chairs += len(taken_places) - number_of_people elif len(taken_places) < number_of_people: all_seats_are_taken = False needed_chairs = number_of_people - len(taken_places) print(f"{needed_chairs} more chairs needed in room {i}") if all_seats_are_taken: print(f"Game On, {number_of_free_chairs} free chairs left")Ето и моето:
Ето и едно мое решение:
number = int(input()) room=0 free_chair=0 need_chairs=0 for i in range(number): chair_info=input().split(" ") chairs=chair_info[0] visitors=int(chair_info[1]) room+=1 free_chair+=len(chairs)-visitors if visitors>len(chairs) : need_chairs = visitors-len(chairs) print(f"{need_chairs} more chairs needed in room {room}") if free_chair>=0: print(f"Game On, {free_chair} free chairs left")