90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
class FitnessRecord:
|
|
def __init__(self, duration, client_code, year, month):
|
|
self.duration = duration
|
|
self.client_code = client_code
|
|
self.year = year
|
|
self.month = month
|
|
|
|
|
|
def solve():
|
|
while True:
|
|
print("\n--- Меню ExamTaskC16 ---")
|
|
print("1. Ввести данные и выполнить расчет")
|
|
print("2. Выход")
|
|
|
|
choice = input("Выберите вариант: ")
|
|
|
|
if choice == "2":
|
|
break
|
|
elif choice == "1":
|
|
try:
|
|
k_code = int(input("Введите код клиента K (10-99): "))
|
|
n = int(input("Введите количество строк N: "))
|
|
|
|
records = []
|
|
for i in range(n):
|
|
print(f"Строка {i + 1} из {n}")
|
|
line = input(
|
|
"Формат <Продолжительность> <Код клиента> <Год> <Номер месяца>: "
|
|
).split()
|
|
|
|
if len(line) != 4:
|
|
print("Ошибка: должно быть 4 числа.")
|
|
continue
|
|
|
|
dur, code, yr, mnth = map(int, line)
|
|
records.append(FitnessRecord(dur, code, yr, mnth))
|
|
|
|
target_records = [r for r in records if r.client_code == k_code]
|
|
|
|
if not target_records:
|
|
print("Нет данных")
|
|
continue
|
|
|
|
years = {}
|
|
for r in target_records:
|
|
if r.duration == 0:
|
|
continue
|
|
if r.year not in years:
|
|
years[r.year] = []
|
|
years[r.year].append(r)
|
|
|
|
if not years:
|
|
print("Нет данных")
|
|
continue
|
|
|
|
results = []
|
|
for year in years:
|
|
year_records = years[year]
|
|
|
|
min_dur = min(r.duration for r in year_records)
|
|
|
|
candidates = [r for r in year_records if r.duration == min_dur]
|
|
|
|
best_month_record = max(candidates, key=lambda x: x.month)
|
|
|
|
results.append(
|
|
{
|
|
"duration": min_dur,
|
|
"year": year,
|
|
"month": best_month_record.month,
|
|
}
|
|
)
|
|
|
|
results.sort(key=lambda x: (x["duration"], x["year"]))
|
|
|
|
print("\nРезультат:")
|
|
for res in results:
|
|
print(f"{res['duration']} {res['year']} {res['month']}")
|
|
|
|
except ValueError:
|
|
print("Ошибка: вводите только целые числа.")
|
|
except Exception as e:
|
|
print(f"Произошла ошибка: {e}")
|
|
else:
|
|
print("Неверный выбор.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
solve()
|