80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
class FitnessRecord:
|
|
def __init__(self, month, year, client_code, duration):
|
|
self.month = int(month)
|
|
self.year = int(year)
|
|
self.client_code = int(client_code)
|
|
self.duration = int(duration)
|
|
|
|
|
|
def run_task_c4():
|
|
while True:
|
|
print("1. Ввести данные и найти результат")
|
|
print("0. Выход")
|
|
|
|
choice = input("Выберите действие: ")
|
|
|
|
if choice == "0":
|
|
break
|
|
elif choice == "1":
|
|
try:
|
|
n_input = input("Введите количество записей N: ")
|
|
if not n_input.isdigit():
|
|
raise ValueError("N должно быть целым числом.")
|
|
n = int(n_input)
|
|
|
|
records = []
|
|
for i in range(n):
|
|
while True:
|
|
try:
|
|
line = input(
|
|
f"Запись {i + 1} (<Месяц> <Год> <Код> <Часы>): "
|
|
).split()
|
|
if len(line) != 4:
|
|
raise ValueError("Нужно ввести 4 числа через пробел.")
|
|
|
|
m, y, c, d = map(int, line)
|
|
|
|
if not (1 <= m <= 12):
|
|
raise ValueError("Месяц: 1-12")
|
|
if not (2000 <= y <= 2010):
|
|
raise ValueError("Год: 2000-2010")
|
|
if not (10 <= c <= 99):
|
|
raise ValueError("Код: 10-99")
|
|
if not (1 <= d <= 30):
|
|
raise ValueError("Часы: 1-30")
|
|
|
|
records.append(FitnessRecord(m, y, c, d))
|
|
break
|
|
except ValueError as e:
|
|
print(f"Ошибка ввода: {e}. Попробуйте еще раз.")
|
|
|
|
if not records:
|
|
print("Список пуст.")
|
|
continue
|
|
|
|
best_rec = records[0]
|
|
for i in range(1, len(records)):
|
|
current = records[i]
|
|
if current.duration > best_rec.duration:
|
|
best_rec = current
|
|
elif current.duration == best_rec.duration:
|
|
if (current.year > best_rec.year) or (
|
|
current.year == best_rec.year
|
|
and current.month >= best_rec.month
|
|
):
|
|
best_rec = current
|
|
|
|
print(
|
|
f"\nРезультат: {best_rec.duration} {best_rec.year} {best_rec.month}"
|
|
)
|
|
|
|
except ValueError as e:
|
|
print(f"Критическая ошибка: {e}")
|
|
else:
|
|
print("Неверный пункт меню.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_task_c4()
|
|
|