Загрузить архив: | |
Файл: 240-0386.zip (9kb [zip], Скачиваний: 82) скачать |
1. ‹€Ž€’Ž€Ÿ €Ž’€ Ž Žƒ€ŒŒˆŽ‚€ˆž “—…ˆŠ€ 10¤ Š‹€‘‘€ ˜ŠŽ‹› N57
€•Œ€Ž‚€ ‘…ƒ…Ÿ Ž ’…Œ… "‘Ž’ˆŽ‚Šˆ".
2. Ž‘’€Ž‚Š€ ‡€„€—ˆ.
„ ä©«, ᮤ¥à¦é¨© ç¨á« ⨯ longint, àᯮ«®¦¥ë¥ ¢ ¯à®¨§¢®«ì®¬
¯®à浪¥. ’ॡã¥âáï àᯮ«®¦¨âì í⨠ç¨á« ¯® ¢®§àáâ¨î, ¨á¯®«ì§ãï ¥ ¡®«¥¥
40 ª¨«®¡©â ®¯¥à⨢®© ¯¬ï⨠¨ ¤¨áª®¢®£® ¯à®áâàá⢠¥ ¡®«¥¥ 祬 ¢ ¤¢
ৠ¡®«ìè¥ ¨á室®£® ä©«.
3. €‹ƒŽˆ’Œ (¬¥â®¤ à¥è¥¨ï).
‘ç« ¨áå®¤ë© ä©« ৡ¨¢¥âáï ªã᪨ ¯® 10000 ç¨á¥«, ª¦¤ë© ªã᮪
á®àâ¨àã¥âáï ¢ ¯¬ï⨠¨ §¯¨á뢥âáï ¢ ®¤¨ ¨§ ¤¢ãå ¢à¥¬¥ëå ä©«®¢, ¯à¨ç¥¬
âª, çâ® ª®«¨ç¥á⢮ ªã᪮¢ ¢ íâ¨å ä©«å ®â«¨ç¥âáï ¥ ¡®«¥¥ 祬 1(¤«¥¥ -
¯¥à¢®ç«ìï á®àâ¨à®¢ª).
‡â¥¬, ¥áª®«ìª® ৠ¢ë¯®«ï¥âáï ®¯¥àæ¨ï "᪫¥¨¢¨¥"(®¤® ¢ë¯®«¥¨¥
®¯¥à樨 "᪫¥¨¢¨¥" ¬ë ¡ã¤¥¬ ¥§ë¢âì "è£"), â.¥ ¤¢ ¨á室ëå
ä©«, ¢ ª®â®àëå 室¨«¨áì ®âá®àâ¨à®¢ë¥ ªã᪨ ª®¯¨àãîâáï ¢ ¤¢ ¤à㣨å
ä©«, ¯à¨ í⮬ ¨§ ¤¢ãå ªã᪮¢, 室ïé¨åáï ¢ à§ëå ä©«å ¨ ¨¬¥îé¨å
®¤¨ª®¢ë¥ ®¬¥à ᮧ¤¥âáï ®¤¨ ®âá®àâ¨à®¢ë© ªã᮪. â®â ªã᮪
§¯¨á뢥âáï ¢ ¯¥à¢ë© ¢ë室®© ä©« ¥á«¨ ¨áå®¤ë¥ ªã᪨ ¨¬¥«¨ ¥ç¥âë¥ ®¬¥à
¨ ¢® ¢â®à®©, ¥á«¨ ¨áå®¤ë¥ ªã᪨ ¨¬¥«¨ ç¥âë¥ ®¬¥à.
4. ‚“’…ŸŸ ‘…–ˆ”ˆŠ€–ˆŸ Žƒ€ŒŒ›.
ਠ¯¨á¨¨ ¯à®£à¬¬ë ¨á¯®«ì§®¢«áì á। Borland Pascal 7.0 ¨
¢áâà®¥ë© ª®¬¯¨«ïâ®à.
„«ï ã᪮८£® ®¡¬¥ á ¤¨áª®¬ ¯à¨¬¥ï«áï ¡«®ª®¢ë© ¢¢®¤-¢ë¢®¤, â.¥
¨ä®à¬æ¨ï ç¨â¥âáï ¨ §¯¨á뢥âáï 楫묨 ª«áâ¥à¬¨. „«ï ®áãé¥á⢫¥¨ï í⮣®
ᯮᮡ ¢¢®¤-¢ë¢®¤ ¡ë« ¯¨á ¬®¤ã«ì(Files), á ¯®¬®éìî ª®â®à®£® ¢¢®¤-¢ë¢®¤
¢¥è¥ ¥ ®â«¨ç¥âáï ®â ®¡ë箣®.
‘奬 ¯à®£à¬¬ë ¯à¥¤¥«ì® ¯à®áâ: áç« ¢ë¯®«ï¥âáï ¯¥à¢®ç«ìï
á®àâ¨à®¢ª(¯à®æ¥¤ãà firstsort), §â¥¬ ¢ë§ë¢¥¬ ᪫¥¨¢¨¥(¯à®æ¥¤ãà
ftrans(in1, in2, out1, out2: workfile);), £¤¥ ¯àë ä©«®¢ ¢á¥ ¢à¥¬ï ¬¥ïîâáï ¨
¯®á«¥ ª¦¤®£® §¯ã᪠¯à®æ¥¤ãàë ¯à®¢¥àï¥âáï ãá«®¢¨¥ ¢ë室.
à®æ¥¤ãà ftrans ®âªà뢥⠢ᥠ䩫ë, §â¥¬ ¢ë¯®«ï¥â ¥áª®«ìª® à§
¯à®æ¥¤ãàã ᫨¢ ®¤®£® ªãáª(onestep) ¨ §ªà뢥â ä©«ë.
5. ŠŽŒŒ…’ˆŽ‚€›‰ ’…Š‘’ Žƒ€ŒŒ›.
{Œ®¤ã«ì Files.
‘¤¥áì ¯¥à¥¯¨áë ¢á¥ ¯à®æ¥¤ãàë ¨ äãªæ¨¨ ¥®¡å®¤¨¬ë¥ ¤«ï à¡®âë á ä©«¬¨,
à¡®âî騥 á ¡«®ª¬¨. ¡®â á ¨¬¨ ®áãé¥á⢫ï¥âáï ⪦¥ ªª ¨ á
®¡ëç묨 ¯à®æ¥¤ãନ ¬®¤ã«ï System.}
unit Files;
interface
const typesize=4;
const bufsize = 2048;
type using=longint;
type buffer = array[1..bufsize] of using;
type pbuffer = ^buffer;
type filemode = (fread, fwrite, closed);
type tfile = record
buf: pbuffer;
mode: filemode;
f: file;
count, leng: integer;
end;
procedure fAssign(var w: tfile; name: string);
procedure fReWrite(var w: tfile);
procedure fReset(var w: tfile);
procedure fPut(var w: tfile; d: using);
procedure fGet(var w: tfile; var d: using);
procedure fClose(var w: tfile);
function fEof(var w: tfile): boolean;
implementation
procedure fAssign(var w: tfile; name: string);
begin
Assign(w.f, name);
w.mode:=closed;
end;
procedure fReWrite(var w: tfile);
begin
if w.mode=closed then
begin
ReWrite(w.f, typesize);
new(w.buf);
w.count:=0;
w.leng:=0;
w.mode:=fwrite;
end;
end;
procedure fReset(var w: tfile);
begin
if w.mode=closed then
begin
Reset(w.f, typesize);
new(w.buf);
BlockRead(w.f, w.buf^, bufsize, w.leng);
w.count:=1;
w.mode:=fread;
end;
end;
procedure fPut(var w: tfile; d: using);
begin
if w.mode=fwrite then
begin
w.count:=w.count+1;
w.buf^[w.count]:=d;
if w.count=bufsize then
begin
BlockWrite(w.f, w.buf^, w.count);
w.count:=0;
end;
end;
end;
procedure fGet(var w: tfile; var d: using);
begin
if (w.mode=fread) then
begin
d:=w.buf^[w.count];
if w.leng=w.count then
begin
BlockRead(w.f, w.buf^, bufsize, w.leng);
w.count:=1;
end else w.count:=w.count+1;
end;
end;
procedure fClose(var w: tfile);
begin
if w.mode=fwrite then BlockWrite(w.f, w.buf^, w.count);
dispose(w.buf);
w.mode:=closed;
Close(w.f);
end;
function fEof(var w: tfile): boolean;
begin
if (w.mode=fread) and (w.leng=0) then fEof:=true
else fEof:=false;
end;
begin
end.
{ª®¥æ files.pas}
{----------------------------------------------------------------------------}
{”©« sort.pas - á®àâ¨à®¢ª ¢ ¯¬ïâ¨.}
var k: integer;
function SwapTops(no: integer): integer;
var t: longint;
begin
if (memo^[2*no+1]>memo^[2*no]) then
begin
t:=memo^[no];
memo^[no]:=memo^[2*no+1];
memo^[2*no+1]:=t;
SwapTops:=2*no+1;
end else
begin
t:=memo^[no];
memo^[no]:=memo^[2*no];
memo^[2*no]:=t;
SwapTops:=2*no;
end;
end;
procedure SwapHalf(no: integer);
var t: longint;
begin
if memo^[no] begin t:=memo^[no]; memo^[no]:=memo^[2*no]; memo^[2*no]:=t; end; end; function Reg(no:
integer): boolean; begin if (2*no)>k then Reg:=true else if (2*no+1)>k then begin SwapHalf(no); Reg:=true; end else if (memo^[2*no]<=memo^[no]) and
(memo^[2*no+1]<=memo^[no]) then Reg:=true else Reg:=false; end; procedure
HalfReg(no: integer); var next:
integer; begin next:=no; while (not Reg(next)) do next:=SwapTops(next); end; procedure
RegTree; var i: integer; begin for i:=k downto 1 do HalfReg(i); end; procedure
SwapLeaves(l1, l2: integer); var t: longint; begin t:=memo^[l1]; memo^[l1]:=memo^[l2]; memo^[l2]:=t; end; procedure
SortMemo(len: integer); begin k:=len; RegTree; for k:=len-1 downto 1 do begin SwapLeaves(1, k+1); HalfReg(1); end; end; {ª®¥æ
sort.pas} {----------------------------------------------------------------------------} {Žá®¢ï
¯®£à¬¬} uses Dos,
Files{®¤ª«î票¥ ¬®¤ã«ï,
®áãé¥á⢫ïî饣®
¢¢®¤-¢ë¢®¤.}; const
memlen=10000;{§¬¥à ¯¬ïâ¨,
à§à¥è¥®© ¤«ï
¨á¯®«ì§®¢¨ï} type tmemo =
array[0 .. memlen] of longint; type pmemo = ^
tmemo;{’¨¯-㪧⥫ì
®á®¢®© ¬áᨢ,
¨á¯®«ì§ã¥¬ë© ¯à®£à¬¬®©} var memo : pmemo; {$I sort.pas}
{®¤ª«î票¥ ä©«,
ᮤ¥à¦é¥£®
¯à®æ¥¤ãàã
á®àâ¨à®¢ª¨ ¬áᨢ
§ ¢à¥¬ï n*(log n), ¥
¨á¯®«ì§ãï
¤®¯®«¨â¥«ì®©
¯¬ïâ¨(á®àâ¨à®¢ª ¤¥à¥¢®¬).} type workfile =
record main{®á®¢®© ä©«}, inf{ä©«,
ᮤ¥à¦é¨© ¤«¨ë
®âá®àâ¨à®¢ëå
ªã᪮¢}: tfile; end;{tfile -
⨯, ®¯à¥¤¥«¥ë© ¢ unit
Files, ª®â®àë© §¬¥ï¥â
ä©«®¢ë¥ ⨯ë} var t1, t2, t3, t4, dest, seur: workfile; {¢à¥¬¥ë¥
ä©«ë}
{¢å®¤®© ¨ ¢ë室®© ä©«} {ˆ¨æ¨«¨§æ¨ï} procedure Init; var tmp: string; begin tmp:=getenv('TEMP'); fAssign(t1.main, tmp+'~fsort-1.tmp'); fAssign(t2.main, tmp+'~fsort-2.tmp'); fAssign(t3.main, tmp+'~fsort-3.tmp'); fAssign(t4.main, tmp+'~fsort-4.tmp'); fAssign(t1.inf, tmp+'~finf-1.tmp'); fAssign(t2.inf, tmp+'~finf-2.tmp'); fAssign(t3.inf, tmp+'~finf-3.tmp'); fAssign(t4.inf, tmp+'~finf-4.tmp'); fAssign(seur.main,ParamStr(1)); fAssign(dest.main,ParamStr(2)); end; {¥à¢®ç«ìï
á®àâ¨à®¢ª} procedure
firstsort(var inp, out1, out2: workfile); var i, k:
longint; begin fReset(inp.main); fRewrite(out1.main); fRewrite(out2.main); fRewrite(out1.inf); fRewrite(out2.inf); new(memo); repeat for i:=1 to memlen do if fEof(inp.main) then begin i:=i-1; break end else fGet(inp.main, memo^[i]); k:=i; sortmemo(k); for i:=1 to k do fPut(out1.main, memo^[i]); fPut(out1.inf, k); if k=memlen then begin for i:=1 to memlen do if fEof(inp.main) then begin i:=i-1; break; end else fGet(inp.main, memo^[i]); k:=i; sortmemo(k); for i:=1 to k do fPut(out2.main, memo^[i]); fPut(out2.inf, k); end; until fEof(inp.main); dispose(memo); fClose(inp.main); fClose(out1.main); fClose(out2.main); fClose(out1.inf); fClose(out2.inf); end; {à®æ¥¤ãà,
ª®¯¨àãîéï
§¤®¥ ª®«¨ç¥á⢮
í«-⮢ ¨§ ®¤®£® ä©« ¢
¤à㣮©. ˆá¯®«ì§ã¥âáï
¯à¨ ᫨¢¨¨ ¤«ï
ª®¯¨à®¢¨ï
®áâ¢è¥©áï çáâ¨
ªãáª(¥á«¨
¤à㣮© ªã᮪
¨ááïª).} procedure
Copy(var inp, out: workfile; c0: longint); var c, n: longint; Done: boolean; begin for c:=c0 downto 1 do begin fGet(inp.main, n); fPut(out.main, n); end; end; {‘«¨¢¥â
¤¢ ®ç¥à¥¤ëå
ªã᪠¨§ ä©«®¢ in1 ¨ in2
¨ §¯¨á뢥⠢ out.} procedure
onestep(var in1, in2, out: workfile; c01, c02: longint); var n1, n2, c1,
c2, c: longint; Done: boolean; begin Done:=false; c1:=c01-1; c2:=c02-1; c:=0; fGet(in1.main, n1); fGet(in2.main, n2); repeat if n1 begin fPut(out.main, n1); c:=c+1; if c1=0 then begin fPut(out.main, n2); c:=c+1; Copy(in2, out, c2); c:=c+c2; Done:=true; end else begin fGet(in1.main, n1); c1:=c1-1; end; end else begin fPut(out.main, n2); c:=c+1; if c2=0 then begin fPut(out.main, n1); c:=c+1; Copy(in1, out, c1); c:=c+c1; Done:=true; end else begin fGet(in2.main, n2); c2:=c2-1; end; end; until Done; end; {à®æ¥¤ãà
®áãé¥á⢫ï¥â ®¤¨
è£(â.¥.
ª®¯¨àã¥â ä©«ë in1 ¨
in2 ¢ out1 ¨ out2, ¯à¨
í⮬ ᪫¥¨¢ï
ªã᪨)} procedure
ftrans(var in1,in2,out1,out2: workfile); var c1, c2, c:
longint; begin fReset(in1.main); fReset(in2.main); fReset(in1.inf); fReset(in2.inf); fRewrite(out1.main); fRewrite(out2.main); fRewrite(out1.inf); fRewrite(out2.inf); while (not fEof(in1.inf)) and (not
fEof(in2.inf)) do begin fGet(in1.inf, c1); fGet(in2.inf, c2); onestep(in1, in2, out1, c1, c2); c:=c1+c2; fPut(out1.inf, c); if (not fEof(in1.inf)) and (not
fEof(in2.inf)) then begin fGet(in1.inf, c1); fGet(in2.inf, c2); onestep(in1, in2, out2, c1, c2); c:=c1+c2; fPut(out2.inf, c); end; end; if fEof(in1.inf) xor fEof(in2.inf) then if fEof(in1.inf) then begin fGet(in2.inf, c2); Copy(in2, out2, c2); fPut(out2.inf, c2); end else if fEof(in2.inf) then begin fGet(in1.inf, c1); Copy(in1, out2, c1); fPut(out2.inf, c1); end; fClose(in1.main); fClose(in2.main); fClose(in1.inf); fClose(in2.inf); fClose(out1.main); fClose(out2.main); fClose(out1.inf); fClose(out2.inf); end; {Š®¯¨à®¢¨¥
ä©« f1 ¢
f2.(ˆá¯®«ì§ã¥âáï
¯à¨ §¢¥à襨¨
à¡®âë ¤«ï ª®¯¨à®¢¨ï
ª®¥ç®£® ä©« ¨§
¢à¥¬¥®©
¤¨à¥ªâ®à¨¨ ¢
㪧ãî).} procedure
FCopy(f1, f2: tfile); var t: longint; begin write('ª®¯¨à®¢¨¥'); fRewrite(f2); fReset(f1); while (not fEof(f1)) do begin fGet(f1, t); fPut(f2, t); end; fClose(f1); fClose(f2); end; {ਨ¬¥â
§ç¥¨¥ True, ¥á«¨ ä©« ®âá®àâ¨à®¢
¨ ¡®«ìè¥ ¥ ¤®
᪫¥¨¢âì. (“á«®¢¨¥
¢ë室)} function Fin:
boolean; begin fReset(t2.main); fReset(t4.main); if fEof(t2.main) then begin Fin:=true; FCopy(t1.main, dest.main); end else if fEof(t4.main) then begin Fin:=true; FCopy(t3.main, dest.main); end else Fin:=false; fClose(t2.main); fClose(t4.main); end; begin writeln; if ParamCount<2 then begin writeln('‘«¨èª®¬ ¬«®
¯à¬¥â஢.'); Exit; end; write('ˆ¨æ¨«¨§æ¨ï...'); Init; writeln('£®â®¢®'); write('¥à¢®ç«ìï
á®àâ¨à®¢ª...'); firstsort(seur, t1, t2); writeln('£®â®¢®'); ReWrite(dest.main.f); Close(dest.main.f); writeln('‘ª«¥¨¢¨¥:'); repeat ftrans(t1, t2, t3, t4); writeln('è£'); if (not Fin) then begin ftrans(t3, t4, t1, t2); writeln('è£'); end; until Fin; writeln('£®â®¢®'); end. {----------------------------------------------------------------------------} 6.
‚…˜ŸŸ ‘…–ˆ”ˆŠ€–ˆŸ. „«ï
ª®à४⮩
à¡®âë
¯à®£à¬¬ë ¥®¡å®¤¨¬ ª®¬¯ìîâ¥à
AT286, 40K ᢮¡®¤®© conventional
¯¬ïâ¨,
®¯¥à樮ï
á¨á⥬ MS-DOS 3.0 ¨«¨
¡®«¥¥ ¯®§¤ïï
¢¥àá¨ï. ‚®§¬®¦ë
¢¥àᨨ
¯à®£à¬¬ë,
¨á¯®«ì§ãî騥
¬¥ìè¥ ¯¬ïâ¨,
¯à®æ¥áá®àë
á«¡¥¥ 286 ¨ â.¤.
ணବ
¨á¯®«ì§ã¥â ¬¥áâ®
¤¨áª¥ ¢¤¢®¥
¡®«ì襥 ¨á室®£®
ä©«(¥ áç¨âïï
ᬠ䩫). 7.
“ŠŽ‚Ž„‘’‚Ž Ž‹œ‡Ž‚€’…‹Ÿ. à¨
§¯ã᪥
¯à®£à¬¬ë
®¡ï§â¥«ì® ¤®«¦
¡ëâì ®¯à¥¤¥«¥
¯¥à¥¬¥ï á।ë TEMP! ”®à¬â
§¯ãáª
¯à®£à¬¬ë: f_sort[.exe] <¢å®¤®©
ä©«> <¢ë室®© ä©«> ணବ
¥ §¤¥â ¨ ªª¨å
¢®¯à®á®¢, çâ®
á¨«ì® ã¯à®é¥â
à¡®âã á ¥©.
¥§ã«ìââ
à¡®âë ¬®¦®
¯®¢¥à¨âì á
¯®¬®éìî ¯à¨«£¥¬®©
ã⨫¨âë f_check, ᮧ¤âì
á«ãç©ë© ¨á室ë©
ä©« - á ¯à®¬®éìî f_make.
à¨ç¨¬¨
®è¨¡®ª ¬®£ãâ
á«ã¦¨âì ¥
ᮮ⢥âá⢨¥ á¨á⥬ë
âॡ®¢¨ï¬, ¨§«®¦¥ë¬
¢ ¯. 6, ¥¤®áââ®ç®¥
¬¥áâ® ¤¨áª¥,
৬¥à(¢ ¡©âå)
¨á室®£® ä©«
¥ ªà⥠4. ‚ ¤®¬
®âç¥â¥
®¯¨á뢥âáï
á¬ï
íä¥ªâ¨¢ï ¢¥àá¨ï
í⮩ ¯à®£à¬¬ë, ® áãé¥áâ¢ãîâ
¢¥àᨨ, ¥
¨á¯®«ì§ãî騥
¢¢®¤-¢ë¢®¤ ¡«®ª¬¨, âॡãî騥
¬¥ìè¥ à¥áãàᮢ
á¨á⥬ë. 8.
Žˆ‘€ˆ… ’…‘’Ž‚.
ணବ¬
â¥áâ¨à®¢«áì
¥®¤®ªââ®, ¢å®¤¥
¨á¯®«ì§®¢«¨áì, ¢
®á®¢®¬, ä©«ë
¨§ á«ãç©ëå
ç¨á¥« ৫¨ç®© ¤«¨ë.
¢ë室¥ ¡ë«¨
¯®«ãç¥ë ä©«ë ⮩¦¥ ¤«¨ë,
¥ ᮤ¥à¦é¨¥
®è¨¡®ª, â.¥. ç¨á«
¢ íâ®å ä©«å ®ª§«¨áì
¢ ¯®à浪¥ ¥
áâண®£®
¢®§àáâ¨ï.
‘®¤¥à¦¨¬®¥ íâ¨å ä©«®¢
¯®«®áâìî ᮢ¯«® á à§ã«ìâ⬨
à¡®âë ¤à㣨å
¯à®£à¬¬
á®àâ¨à®¢ª¨ â¥å
¦¥ ¢å®¤ëå ä©«å,
ç⮠ᨫì®
ᨦ¥â
¢¥à®ïâ®áâì
¤¨ä¥ªâ®¢
¯à®£à¬¬ë. à¨
â¥áâ¨à®¢¨¨
¨á¯®«ì§®¢«¨áì
®¯¥à樮ë¥
á¨á⥬ë MS-DOS 6.22, Windows`95,
ª®¬¯ìîâ¥àë PC AT 486DX4-100,
486SX-25, à¡®âî騥 á
«®ª«ìë¬ ¢¨ç¥áâ¥à®¬,
஡®ç¨¥ áâ樨
486DX-40, 386SX, à¡®âî騥
¢ á¥â¨ Novell. ¥§ã«ìââë
â¥áâ¨à®¢¨ï(
ä©«¥ ৬¥à®¬ 4M)
§¥á¥ë ¢ â¡«¨æã: ª®¬¯ìîâ¥à
à¡®â
¢ á¥â¨
¢à¥¬ï à¡®âë 486DX4-100 ¥â 3 ¬¨. 486SX-25 ¥â 7 ¬¨. 486DX-40 ¤ 386SX ¤