Advertisement
Denny707

Untitled

May 10th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. procedure Quantita_Tablet(in:N,M,Tablet_Negozio,Tablet_Magazzino; out:Tablet_Totale)
  2. var M,N,i_totale: integer
  3. var Tablet_Negozio: array(1..M,1..2) of integer
  4. var Tablet_Magazzino: array(1..N,1..2) of integer
  5. var Tablet_Totale: array(1..M+N,1..2) of integer
  6. begin
  7. while(i<M && j<N) do
  8. if(Tablet_Negozio[i][1]==Tablet_Magazzino[j][1]) then
  9. Tablet_Totale[i_totale][0]:=Tablet_Magazzino[j][0]+Tablet_Negozio[i][0]
  10. Tablet_Totale[i_totale][1]:=Tablet_Magazzino[j][1]
  11. i:=i+1
  12. j:=j+1
  13. else if(Tablet_Magazzino[j][1]<Tablet_Negozio[i][1]) then
  14. Tablet_Totale[i_totale][0]:=Tablet_Magazzino[j][0]
  15. Tablet_Totale[i_totale][1]:=Tablet_Magazzino[j][1]
  16. j:=j+1
  17. else
  18. Tablet_Totale[i_totale][0]:=Tablet_Negozio[j][0]
  19. Tablet_Totale[i_totale][1]:=Tablet_Negozio[j][1]
  20. i:=i+1
  21. endif
  22. i_totale:=i_totale+1
  23. end while
  24.  
  25. while(i<M) do
  26. Tablet_Totale[i_totale][0]:=Tablet_Negozio[j][0]
  27. Tablet_Totale[i_totale][1]:=Tablet_Negozio[j][1]
  28. i:=i+1
  29. end while
  30.  
  31. while(j<N) do
  32. Tablet_Totale[i_totale][0]:=Tablet_Magazzino[j][0]
  33. Tablet_Totale[i_totale][1]:=Tablet_Magazzino[j][1]
  34. j:=j+1
  35. end while
  36. end
  37.  
  38. program esercizio_3
  39. var M,N: integer
  40. var Tablet_Negozio: array(1..M,1..2) of integer
  41. var Tablet_Magazzino: array(1..N,1..2) of integer
  42. var Tablet_Totale: array(1..M+N,1..2) of integer
  43. begin
  44. read M,N
  45. for i:=0,M do
  46. read Tablet_Negozio[i][0]
  47. read Tablet_Negozio[i][1]
  48. endfor
  49. for i:=0,N do
  50. read Tablet_Negozio[i][0]
  51. read Tablet_Negozio[i][1]
  52. endfor
  53.  
  54. Quantita_Tablet(N,M,Tablet_Negozio,Tablet_Magazzino,Tablet_Totale)
  55.  
  56. for i:=0,N+M do
  57. read Tablet_Totale[i][0]
  58. read Tablet_Totale[i][1]
  59. endfor
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement