Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
23
Добавлен:
28.06.2014
Размер:
10.33 Кб
Скачать
{•ниЁа®ў ­ЁҐ}
program Lab5_Zaharov;
uses crt;
type xSET=set of 0..99;
MAS=array [1..100] of integer;{ЋЇЁб ­ЁҐ вЁЇ  ¬ ббЁў }
var
V : MAS;
M, M1 : xSET;
i, S, k, P, N, L, b, H : integer;
fl : boolean;
memV,KMemV : real;

{Џа®жҐ¤га  ўлў®¤   ­®¬ «ЁЁ ­  нЄа ­}
procedure Anomaliya (text1, text2 : string; var p_repeat : boolean);
var p_key : char;
y : integer;
i,k : byte;
begin
clrscr;
if p_repeat=true then k:=4 else k:=2;
textcolor(k);
y:=(82 - 4 - length (text1)) div 2;
gotoxy (y,10); write ('Й'); for i:=1 to length (text1)+2 do write ('Н'); write ('»');
gotoxy (y,11); write ('є '); textcolor (k+240); write (text1); textcolor (k); write (' є');
gotoxy (y,12); write ('И'); for i:=1 to length (text1)+2 do write ('Н'); write ('ј');
if length(text2)<>0
then
begin
textcolor (8);
y:=(82 - 8 - length (text2)) div 2;
gotoxy (y,13); write ('Ъ'); for i:=1 to length (text2)+6 do write ('Д'); write ('ї');
gotoxy (y,14); write ('і ',text2,' і');
gotoxy (y,15); write ('А'); for i:=1 to length (text2)+6 do write ('Д'); write ('Щ');
end;
gotoxy(1,1);
if p_repeat=true then
repeat
sound (400); delay (40000);
nosound; delay (50000);
until keypressed
else repeat until keypressed;
k:=1; p_repeat:=true;
gotoxy (60,20); textcolor (blue); write ('ЪДДДДДДДДДДДї');
gotoxy (60,23); textcolor (blue); write ('АДДДДДДДДДДДЩ');
repeat gotoxy (60,21); clreol;
textcolor (15);
textbackground (0);
textcolor (blue); write ('і');
textcolor (15);
if k=1 then textbackground(blue) else textbackground(0);
write (' ЏЋ‚’Ћђ€’њ ');
textbackground (0);
textcolor (blue); write ('і');
textcolor (15);

gotoxy (60,22); clreol;
textcolor (15);
textbackground (0);
textcolor (blue); write ('і');
textcolor(15);
if k=2 then textbackground(blue) else textbackground(0);
write (' ‡Ђ‚…ђ€’њ ');
textbackground (0);
textcolor (blue); write ('і');
textcolor (15);
repeat
p_key:=readkey;
until (p_key=chr(72)) or (p_key=chr(80)) or (p_key=chr(13));
if ((p_key=chr(72)) or (p_key=chr(80))) and (k=1)
then begin k:=2; p_repeat:=false; end
else if ((p_key=chr(72)) or (p_key=chr(80))) and (k=2)
then begin k:=1; p_repeat:=true; end
else
if p_key=chr(13)
then k:=3;
until (k=3);
clrscr;
end;

{Џа®жҐ¤га  д®а¬Ёа®ў ­Ёп ¬­®¦Ґбвў  Њ ¬®й­®бвЁ ђ Ё§ н«Ґ¬Ґ­в®ў 0,1,2..P-1}
procedure VVODset (X : xSET; Y : integer);
var
z,T : integer;
begin
randomize;
gotoxy (((83-(Y*3)) div 2),6);
write ('[ ');
z:=0;
while z<>Y do
begin
T:=random (Y);
if not (T in X)
then
begin
z:=z+1;
X:=X+[T];
write (T,' ');
end;
end;
writeln (']');
end;

{Џа®жҐ¤га  ўлў®¤  ¬ ббЁў  Ї ¬пвЁ V}
procedure VIVODarray (X : MAS; Y : integer);
var
z,T,x1,y1 : integer;
begin
T:=0; x1:=wherex; y1:=wherey;
gotoxy (((80-(Y*3)) div 2),25);
write ('[');
for z:=1 to Y do
if X[z]=(-1)
then write (' * ')
else write (X[z]:2,' ');
write (']');
gotoxy (x1,y1);
end;

{ЋЇаҐ¤Ґ«Ґ­Ёп Їа®жҐ­в  § Ї®«­Ґ­­®© Ї ¬пвЁ}
function Memory (X : MAS; Y : integer) : real;
var MemoryX : real;
z : integer;
begin
MemoryX:=0;
for z:=1 to Y do
if X[z]<>(-1)
then MemoryX:=MemoryX+(100/Y);
Memory:=MemoryX;
end;

{ѓ« ў­ п Їа®Ја ¬¬ }
begin
repeat
clrscr;
writeln;
writeln (' ‹ Ў®а в®а­ п а Ў®в  # 5');
writeln (' •ниЁа®ў ­ЁҐ.');
writeln;
write ('‚ўҐ¤ЁвҐ ¤«Ё­г ¬­®¦Ґбвў  Њ >>> ');
read (P);
if (P<=0) or (P>20)
then
begin
fl:=true;
Anomaliya ('‚­Ё¬ ­ЁҐ, ®иЁЎЄ !!!','„«Ё­  ¬­®¦Ґбвў  Њ ¤®«¦­  Ўлвм 0<ђ<=20!!!',fl);
end
else
begin
gotoxy (40,5);
write ('‚ўҐ¤ЁвҐ ¤«Ё­г ¬ ббЁў  V >>> ');
readln (N);
if (N<=0) or (N>P)
then
begin
fl:=true;
Anomaliya ('‚­Ё¬ ­ЁҐ, ®иЁЎЄ !!!','„«Ё­  ¬ ббЁў  V ¤®«¦­  Ўлвм 0<N<=P!!!',fl);
end
else
begin
VVODset (M,P); {”®а¬Ёа®ў ­ЁҐ ¬­®¦Ґбвў }
for k:=1 to N do V[k]:=-1; {ЋЎ­г«Ґ­ЁҐ п祥Є Ї ¬пвЁ}
writeln ('K-зЁб«® а §¬ҐйҐ­­ле н«Ґ¬Ґ­в®ў; S-зЁб«® Їа®Ў ¤® а §аҐиҐ­Ёп i-®© Є®««Ё§ЁЁ');
writeln ('ЪДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДВДДДДДДДВДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДї');
writeln ('і Џ ¬пвм іќ«Ґ¬Ґ­ві €­д®а¬ жЁп ® а §¬ҐйҐ­ЁЁ н«Ґ¬Ґ­в  і');
writeln ('ГДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДЕДДДДДДДЕДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДґ');
k:=0; MemV:=0;
M1:=[];
while (k<(p-1)) and (MemV<>100) do
begin
repeat
H:=random(p);
until not (H in M1);
M1:=M1+[H];
i:=H-(H div N)*N+1;
if V[i]<>(-1) {Џа®ўҐаЄ  § ­пв  «Ё п祩Є  Ї ¬пвЁ}
then
begin
S:=1; fl:=false;
{Џ®ЁбЄ бў®Ў®¤­®© п祩ЄЁ Ї ¬пвЁ}
while ((i+S)<=P) and (fl=false) do
begin
if V[i+S]=(-1)
then
begin
V[i+S]:=H;
MemV:=Memory(V,N);
k:=k+1;
fl:=true;
VIVODarray(V,N);
write ('і ');
{‚лў®¤ ®Ўкс¬  § ­пв®© Ї ¬пвЁ}
KMemV:=MemV; L:=0;
while KMemV>0 do
begin
if L<=20 then write ('Ы');
KMemV:=KMemV-5; L:=L+1;
end;
if L<>20 then
for b:=(L+1) to 20 do write ('°');
writeln (' ',MemV:5:1,'% і ',H:3,
' і ђ §аҐиЁ¬ п Є®««Ё§Ёп. K=',k:2,'; S=',S:2,' і');
end
else S:=S+1;
end;
if fl=false
then
begin
MemV:=Memory(V,N);
fl:=true;
VIVODarray(V,N);
write ('і ');
{‚лў®¤ ®ЎкҐ¬  § ­пв®© Ї ¬пвЁ}
KMemV:=MemV; L:=0;
while KMemV>0 do
begin
if L<=20 then write ('Ы');
KMemV:=KMemV-5; L:=L+1;
end;
if L<>20 then
for b:=(L+1) to 20 do write ('°');
writeln (' ',MemV:5:1,'% і ',H:3,
' і ЌҐа §аҐиЁ¬ п Є®««Ё§Ёп. K=',k:2,'; і');
end;
end
else
begin
V[i]:=H;
k:=k+1;
MemV:=Memory(V,N);
VIVODarray(V,N);
write ('і ');
{‚лў®¤ ®ЎкҐ¬  § ­пв®© Ї ¬пвЁ}
KMemV:=MemV; L:=0;
while KMemV>0 do
begin
if L<=20 then write ('Ы');
KMemV:=KMemV-5; L:=L+1;
end;
if L<>20 then
for b:=(L+1) to 20 do write ('°');
writeln (' ',MemV:5:1,'% і ',H:3,
' і Љ®««Ё§ЁЁ ­Ґ ў®§­ЁЄ«®. і');
end;
end;
write('АДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДБДДДДДДДБДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДЩ');
readln;
fl:=false;
Anomaliya ('Џа®Ја ¬¬  ўлЇ®«­Ґ­  гбЇҐи­®.','',fl);
end;
end;
until fl=false;
end.
Соседние файлы в папке LAB5