Розв’язок задачі з Абрамова №517е
Сер 18

Всі умови | Умова: Даний файл f, містить відомості про іграшки: вказується назва іграшки (наприклад, лялька, кубики, м'яч, конструктор і т. д.), її вартість в копійках і вікові межі дітей, для яких іграшка призначена (наприклад, для дітей від двох до п'яти років). Отримати такі відомості чи можна підібрати іграшку, яку, крім м'яча, відповідну дитині 3 років, і додатково м'яч так, щоб сумарна вартість іграшок не перевершувала 5 руб.?; (С.А. Абрамов, Г.Г. Гнездилова,Е.Н. Капустина, М.И. Селюн. Задачи по программированию. - Вологда, 2000. - №517)
program Pr517; type TToi = record name : string[20]; price : integer; min_age : byte; max_age : byte; end; var i : byte; f : file of TToi; t : TToi; bol_min_price : integer; toi_min_price : integer; begin assign(f,'in'); reset(f); bol_min_price := 99999999; toi_min_price := 99999999; while not eof(f) do begin read(f,t); if (t.name = 'ball') and (t.price < bol_min_price) and (t.min_age <=3) and (t.max_age >=3) then bol_min_price := t.price; if (t.name <> 'ball') and (t.price < toi_min_price) and (t.min_age <=3) and (t.max_age >=3) then toi_min_price := t.price; end; close(f); if toi_min_price+bol_min_price < 500 then writeln('YES') else writeln('NO'); readln; end.