У меня есть план сделать что-нибудь, чтобы решить эту проблему:
У вас есть 7 фишек, которые сейчас в ходу. у каждого загружен какой-то груз. А также есть where
запись на каждом. Последние могут быть либо track
означает бег (или ушел по бездорожью) или tobeauty
означает, что он достиг своего финиша. Где .cargo = -1
означает, что его больше нет. И, наконец, мне нужен один из трех: все пропало, по крайней мере, один на финише, а другие либо на финише, либо ушли, и шоу не продолжается, так что ни один из этих двух. Будут проверены только первые два, поэтому thrd будет чем-то еще.
Наконец-то я сделал это вот так:
uses crt;
type
trail_type = (blue ,desert ,white ,green ,violet ,wood ,coldgreen) ;
palmtree = (none ,apple ,appricot ,grape ,pineapple ,lemon);
catchinon = (track, tobeauty);
type
ontherun = Record
trail : trail_type;
cargo : Currency;
miles : Integer;
where : catchinon;
end;
Var
rec_b : array[1..7] of ontherun;
fruit : palmtree;
k : Integer;
Function Ternary(x : Boolean ; b : palmtree ; c : palmtree ) : palmtree;
begin
if x then
Ternary := b
else
Ternary := c;
end;
begin
{testing part}
{ rec_b[4].cargo := -1;
rec_b[5].where := tobeauty;
rec_b[7].where := tobeauty;
rec_b[1].cargo := -1;
rec_b[3].where := tobeauty;
fruit := none;}
{for k := 1 to 7 do
rec_b[k].where := tobeauty;}
for k := 1 to 7 do
rec_b[k].cargo := -1;
rec_b[7].where := tobeauty;
rec_b[7].cargo := 20;
{testing part ended}
fruit := none;
for k := 1 to 7 do
begin
fruit := Ternary((rec_b[k].where = tobeauty) and ( fruit in [none , pineapple]), appricot , fruit );
fruit := Ternary((rec_b[k].cargo = -1) and ( not (fruit in [grape])), lemon , fruit);
fruit := Ternary((rec_b[k].where = track) and ( fruit in [ none , appricot , apple , pineapple]), grape , fruit);
fruit := Ternary((rec_b[k].cargo = -1) and ( fruit in [lemon ]), pineapple , fruit);
fruit := Ternary((rec_b[k].where = tobeauty) and ( fruit in [pineapple, appricot]), apple , fruit );
end;
Writeln(fruit);
end.
Вы знаете какие-нибудь уловки?