Guest User

Untitled

a guest
Apr 26th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. {
  2. AUTOR:
  3. FICHERO:
  4. DESCRIPCION:
  5. }
  6. PROGRAM almacen(input, output);
  7.  
  8. CONST
  9. FIL = 4;
  10. COL = 6;
  11.  
  12. TYPE
  13. tpAlmacen = ARRAY[1..FIL,1..COL] OF boolean;
  14. tpSolucion = RECORD
  15. fila,columna:integer;
  16. { ... }
  17. end;
  18. VAR
  19. a : tpAlmacen;
  20. tam : integer;
  21. resultado: tpSolucion;
  22. solucion_fila, solucion_columna:integer;
  23. FUNCTION buscasitios(M:tpAlmacen; tamano:integer):tpSolucion;
  24. VAR
  25. resultado:tpSolucion;
  26. x,y,contador:integer;
  27. hueco:boolean;
  28. solucion_fila, solucion_columna:integer;
  29. BEGIN
  30. x:=1;
  31. hueco:=false;
  32. while (x <= FIL) and (not hueco) do
  33. begin
  34. y:=1;
  35. contador:=0;
  36. while (y <= COL) and (not hueco) do
  37. begin
  38. if M[x,y]=true
  39. then contador:= 0
  40. else begin
  41. contador:= contador + 1;
  42. if contador=tamano
  43. then begin
  44. hueco:= true;
  45. solucion_fila:=x;
  46. solucion_columna:=y-tamano+1;
  47. end;
  48. end;
  49. y:=y+1;
  50. end;
  51. x:=x+1;
  52. end;
  53. if not hueco
  54. then begin solucion_fila:=0; solucion_columna:=0
  55. end;
  56. buscasitios:=resultado;
  57. end;
  58. {Funcion que busca en cada fila si hay el numero de huecos necesarios para el paquete}
  59. BEGIN
  60. { write('Dame el tamaño del hueco que hay que buscar: '); }
  61. { readln(tam); }
  62. {En caso de querer modificar el tamano del paquete}
  63. tam:=3;
  64.  
  65.  
  66. { Tamaño de producto}
  67.  
  68. { Matriz. true = ocupado, false = libre }
  69. a[1,1] := false;
  70. a[1,2] := false;
  71. a[1,3] := true;
  72. a[1,4] := true;
  73. a[1,5] := false;
  74. a[1,6] := false;
  75. a[2,1] := false;
  76. a[2,2] := false;
  77. a[2,3] := false;
  78. a[2,4] := false;
  79. a[2,5] := true;
  80. a[2,6] := false;
  81. a[3,1] := true;
  82. a[3,2] := true;
  83. a[3,3] := false;
  84. a[3,4] := true;
  85. a[3,5] := false;
  86. a[3,6] := true;
  87. a[4,1] := true;
  88. a[4,2] := true;
  89. a[4,3] := false;
  90. a[4,4] := false;
  91. a[4,5] := false;
  92. a[4,6] := false;
  93.  
  94. { Llamada a la función y salida de datos }
  95.  
  96. resultado:= buscasitios(a,tam);
  97. if( solucion_fila > 0) and (solucion_columna > 0)
  98. then begin writeln('el hueco que buscamos comenzara en la columna',solucion_columna,' de la fila',solucion_fila, ' y ocupara ',tam, 'sitios');
  99.  
  100. end
  101. else
  102. writeln('no hay huecos suficientes consecutivos en el almacen para el paquete dado');
  103. readln;
  104. { Comprobacion de que hay suficientes huecos en la matriz para el paquete}
  105. end.
Add Comment
Please, Sign In to add comment