4L2FSORT.PAS 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. Uses DOS;
  2. Type
  3. Ftype = integer;
  4. FDAT = file of Ftype;
  5. Var
  6. H1, M1,
  7. H2, M2,
  8. S1, S2,s3 : Word;
  9. Ftext : text;
  10. A,B,C,D,T : ^FDAT;
  11. curA, prevA,
  12. curB, prevB : Ftype;
  13. sendA,sendB,
  14. fendA,fEndB,
  15. ns : boolean;
  16. TLen : longint;
  17. {------------------------------}
  18. Function NewA : FType;
  19. var
  20. ret : Ftype;
  21. begin
  22. If EOF(A^) then
  23. begin
  24. FendA := true;
  25. NewA := -1;
  26. end
  27. else
  28. begin
  29. Read(A^,ret);
  30. NewA := ret;
  31. end;
  32. end;
  33. Function NewB : FType;
  34. var
  35. ret : Ftype;
  36. begin
  37. If EOF(B^) then
  38. begin
  39. FendB := true;
  40. NewB := -1;
  41. end
  42. else
  43. begin
  44. Read(B^,ret);
  45. NewB := ret;
  46. end;
  47. end;
  48. Procedure Init;
  49. var
  50. cur : Ftype;
  51. curw : boolean;
  52. begin
  53. New(A);
  54. New(B);
  55. New(C);
  56. New(D);
  57. Assign(A^,'file1.dat');
  58. Assign(B^,'file2.dat');
  59. Assign(C^,'file3.dat');
  60. Assign(D^,'file4.dat');
  61. Rewrite(A^);
  62. Rewrite(B^);
  63. Rewrite(C^);
  64. Rewrite(D^);
  65. {--------}
  66. curw := true;
  67. Assign(Ftext,'input.txt');
  68. Reset(Ftext);
  69. Tlen := 0;
  70. repeat
  71. read(Ftext,cur);
  72. if curw then Write(A^,cur) else Write(B^,cur);
  73. curw := not curw;
  74. inc(Tlen);
  75. until EOF(Ftext);
  76. Dec(Tlen);
  77. Reset(A^);
  78. Reset(B^);
  79. Close(Ftext);
  80. end;{Init}
  81. {---------------}
  82. BEGIN
  83. Init;
  84. WriteLn('� ç¨­ ¥¬ á®àâ¨à®¢ªã ',Tlen,' í«¥¬¥­â®¢');
  85. GetTime(H1,M1,S1,S2);
  86. WriteLn('’¥ªã饥 ¢à¥¬ï: ',H1,' ç á®¢ ',M1,' ¬¨­ãâ ',S1,' ᥪ㭤');
  87. preva := -maxint;
  88. prevb := preva;
  89. repeat
  90. ns := true;
  91. curA := NewA;
  92. curB := NewB;
  93. fendA := False;
  94. fendB := false;
  95. repeat
  96. sendA := false;
  97. sendB := false;
  98. if (not fendA) and (not fendB) then
  99. repeat
  100. if curA < curB then
  101. begin
  102. Write(C^,curA);
  103. prevA := curA;
  104. curA := newA;
  105. if curA < prevA then sendA := true;
  106. end
  107. else
  108. begin
  109. Write(C^,curB);
  110. prevB := curB;
  111. curB := newB;
  112. if curB < prevB then sendB := true;
  113. end
  114. until sendA or sendB or fendA or fendB;
  115. if sendA or fendA then
  116. repeat
  117. Write(C^,curB);
  118. prevB := curB;
  119. curb:=NewB;
  120. if curb < prevB then sendB := true;
  121. until SendB or FendB
  122. else
  123. repeat
  124. Write(C^,curA);
  125. prevA := curA;
  126. cura:=NewA;
  127. if cura < prevA then sendA := true;
  128. until SendA or FendA;
  129. if (not fendA) and (not fendB) then ns := false;
  130. T := C;
  131. C := D;
  132. D := T;
  133. if FendA and (not FendB) then
  134. repeat
  135. Write(C^,curB);
  136. ns := false;
  137. curB := NewB;
  138. until FendB
  139. else
  140. if FendB and (not FendA) then
  141. repeat
  142. Write(C^,curA);
  143. cura:=NewA;
  144. ns := false;
  145. until FendA;
  146. until fendA or fendB;
  147. T := C;
  148. C := A;
  149. A := T;
  150. T := D;
  151. D := B;
  152. B := T;
  153. Reset(A^);
  154. Reset(B^);
  155. RewRite(C^);
  156. RewRite(D^);
  157. until (FendA or FendB) and ns;
  158. WriteLn('‘®àâ¨à®¢ª  ',Tlen,' í«¥¬¥­â®¢ § ª®­ç¥­  !');
  159. GetTime(H2,M2,S2,S3);
  160. WriteLn('’¥ªã饥 ¢à¥¬ï: ',H2,' ç á®¢ ',M2,' ¬¨­ãâ ',S2,' ᥪ㭤');
  161. H1 := H2 - H1;
  162. if M1 > M2 then
  163. begin
  164. Dec(h1);
  165. M1 := M2-M1+60;
  166. end
  167. else M1 := M2-M1;
  168. if S1 > S2 then
  169. begin
  170. Dec(M1);
  171. S1 := S2-S1+60;
  172. end
  173. else S1 := S2-S1;
  174. WriteLn('‡ âà ç¥­®: ',H1,' ç á®¢ ',M1,' ¬¨­ãâ ',S1,' ᥪ㭤');
  175. WriteLn('”®à¬¨à㥬 ¢ë室­®© ä ©«...');
  176. Assign(Ftext,'output.txt');
  177. Rewrite(Ftext);
  178. repeat
  179. Read(B^,curA);
  180. WriteLn(Ftext,curA);
  181. until EOF(B^);
  182. Close(A^);
  183. Close(B^);
  184. Close(C^);
  185. Close(D^);
  186. Close(Ftext);
  187. Dispose(A);
  188. Dispose(B);
  189. Dispose(C);
  190. Dispose(D);
  191. END.