Guest User

Untitled

a guest
Jan 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.32 KB | None | 0 0
  1. uses
  2.   SysUtils;
  3. type tovar=record
  4.   name:string;
  5.   count:integer;
  6. end;
  7. var
  8. shop:array [0..1005] of tovar;
  9. man:array [0..1005] of tovar;
  10. i,m,n,ans :integer;
  11. s:string;
  12. x:tovar;
  13.  
  14. function Exist(name:string):integer;
  15. var i:integer;
  16. begin
  17. result:=0;
  18.   for I := 1 to m do
  19.     if shop[i].name=name then
  20.       begin
  21.         result:=i;
  22.         break;
  23.       end;
  24. end;
  25.  
  26.  
  27. function BuyIt(var x:tovar):boolean;
  28. var i:integer;
  29. begin
  30. result:=true;
  31.   i:=Exist(x.name);
  32.   if (i>0) then
  33.     if (shop[i].count<x.count) then
  34.       begin
  35.         x.count:=shop[i].count;
  36.         result:=false;
  37.       end
  38.       else dec(shop[i].count,x.count)
  39.            else begin end;
  40. end;
  41.  
  42. procedure push(x:tovar);
  43. begin
  44.   inc(n);
  45.   man[n]:=x;
  46. end;
  47.  
  48. function pop :tovar;
  49. begin
  50.   result:=man[n];
  51.   dec(n);
  52. end;
  53.  
  54. procedure Exchange(x:tovar);
  55. var y:tovar;
  56. begin
  57. y:=pop;
  58. push(x);
  59. push(y);
  60. end;
  61.  
  62. begin
  63. ans:=0;
  64. Readln(m);
  65. for I := 1 to m  do
  66.   begin
  67.     Readln(s);
  68.     shop[i].count:=strtoint(copy(s,1,pos(' ',s)-1));
  69.     Delete(s,1,pos('of',s)+2);
  70.     shop[i].name:=s;
  71.   end;
  72. Readln(n);
  73. for I := n+1 downto 2  do
  74.   begin
  75.     Readln(s);
  76.     man[i].count:=strtoint(copy(s,1,pos(' ',s)-1));
  77.     Delete(s,1,pos('of',s)+2);
  78.     man[i].name:=s;
  79.   end;
  80. inc(n);
  81. man[1].name:='3to ya!!!';
  82. repeat
  83. inc(ans);
  84. x:=pop;
  85. if not(BuyIt(x)) then Exchange(x);
  86. until man[n].name='3to ya!!!';
  87. Writeln(ans);
  88. end.
Add Comment
Please, Sign In to add comment