Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- SysUtils;
- type tovar=record
- name:string;
- count:integer;
- end;
- var
- shop:array [0..1005] of tovar;
- man:array [0..1005] of tovar;
- i,m,n,ans :integer;
- s:string;
- x:tovar;
- function Exist(name:string):integer;
- var i:integer;
- begin
- result:=0;
- for I := 1 to m do
- if shop[i].name=name then
- begin
- result:=i;
- break;
- end;
- end;
- function BuyIt(var x:tovar):boolean;
- var i:integer;
- begin
- result:=true;
- i:=Exist(x.name);
- if (i>0) then
- if (shop[i].count<x.count) then
- begin
- x.count:=shop[i].count;
- result:=false;
- end
- else dec(shop[i].count,x.count)
- else begin end;
- end;
- procedure push(x:tovar);
- begin
- inc(n);
- man[n]:=x;
- end;
- function pop :tovar;
- begin
- result:=man[n];
- dec(n);
- end;
- procedure Exchange(x:tovar);
- var y:tovar;
- begin
- y:=pop;
- push(x);
- push(y);
- end;
- begin
- ans:=0;
- Readln(m);
- for I := 1 to m do
- begin
- Readln(s);
- shop[i].count:=strtoint(copy(s,1,pos(' ',s)-1));
- Delete(s,1,pos('of',s)+2);
- shop[i].name:=s;
- end;
- Readln(n);
- for I := n+1 downto 2 do
- begin
- Readln(s);
- man[i].count:=strtoint(copy(s,1,pos(' ',s)-1));
- Delete(s,1,pos('of',s)+2);
- man[i].name:=s;
- end;
- inc(n);
- man[1].name:='3to ya!!!';
- repeat
- inc(ans);
- x:=pop;
- if not(BuyIt(x)) then Exchange(x);
- until man[n].name='3to ya!!!';
- Writeln(ans);
- end.
Add Comment
Please, Sign In to add comment