Advertisement
CrazyDiver

IT homework

Dec 12th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. procedure Read4Nums(var n1,n2,n3,n4:longint);
  2. begin
  3. read(n1,n2,n3,n4); //read 4 nums
  4. end;
  5. procedure FindCountMethods(i1,i2,i3:longint;a,b,c,n:longint);
  6. var i,j,k,mtd:longint;
  7. begin
  8. mtd:=0;
  9. for i := 0 to i1 do //repeat cycle eq weight of prod, that we can buy from 1st box
  10. for j := 0 to i2 do //repeat cycle eq weight of prod, that we can buy from 2nd box
  11. for k := 0 to i3 do //repeat cycle eq weight of prod, that we can buy from 3d box
  12. if i * a + j * b + k * c = n then //if weight of all product we can buy matches weight of product we need to but then
  13. mtd := mtd + 1; //add to number of method 1
  14. writeln(mtd); //write method
  15. end;
  16. procedure WriteMtds(i1,i2,i3:longint;a,b,c,n:longint);
  17. var i,j,k:longint;
  18. begin
  19. for i := 0 to i1 do //repeat cycle eq weight of prod, that we can buy from 1st box
  20. for j := 0 to i2 do //repeat cycle eq weight of prod, that we can buy from 2nd box
  21. for k := 0 to i3 do //repeat cycle eq weight of prod, that we can buy from 3d box
  22. if i * a + j * b + k * c = n then //if weight of all product we can buy matches weight of product we need to but then
  23. writeln(i, ' ', j, ' ', k); //write weight of product that we can bout from 1st box, 2nd box, 3d box with spaces
  24. end;
  25. var
  26. n, a, b, c, mtd, i1, i2, i3, i, j, k: longint;
  27.  
  28. begin
  29. read(a, b, c, n); //read read wheight of every type of the product and count of product, need to buy
  30. mtd := 0; //firstly num of methods eq 0
  31. i1 := n div a; //weight of product from 1st box
  32. i2 := n div b; //weight of product from 2nd box
  33. i3 := n div c; //weight of product from 3d box
  34. FindCountMethods(i1,i2,i3,a,b,c,n); //Find and Write count of methods that product can be distributed
  35. WriteMtds(i1,i2,i3,a,b,c,n); //write this methods
  36. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement