Введем слово (1) допустим, что его рекорд 2000, слово (2) – 500 и т.д. Не больше 7 слов.
(1) – 2000
(2) – 500
(3) – 1500
(4) – 5000
(5) – 100
(6) – 750
(7) – 2400
Как сделать, чтобы в файле слова сохранились по возрастанию рекордов в виде:
(4) – 5000
(7) – 2400
(1) – 2000
(3) – 1500
(6) – 750
(2) – 500
(5) – 100
При вводе слова с рекордом 1900 или любым другим, оно вставало на нужную позицию, в данном случае между словами (1) и (3), и т.д.
uses crt, graph;
function get_input(xst, yst: integer): string;
var
stop: boolean;
in_str: string;
ch: char;
begin
in_str := '';
stop := false;
repeat
setbkcolor(white);
setfillstyle(solidfill, black);
settextjustify(lefttext, toptext);
bar(xst, yst, xst + 50 * textwidth('W'), yst + textheight('W') + 2);
setcolor(blue);
outtextxy(succ(xst),
succ(yst), in_str);
ch := readkey;
if ch = #0 then readkey
else if ch = #13 then stop := true
else if (ch = #8) then begin
if length(in_str) > 0 then
delete(in_str, length(in_str), 1)
end
else in_str := in_str + ch;
until stop;
get_input := in_str
end;
var
gD: Integer;
gM: Integer;
ErrCode: Integer;
f:file of string;
s: string;
begin
gD := Detect;
InitGraph(gD, gM,'c:\bgi');
ErrCode := GraphResult;
setcolor(blue);
rectangle(240,200,390,300);
setfillstyle(1,green);
floodfill(241,201,blue);
setcolor(blue);
rectangle(260,250,370,270);
setfillstyle(1,white);
floodfill(261,251,blue);
setcolor(red);
outtextxy(260,215,'Enter you name');
if ErrCode <> grOk then begin
Writeln('Graphics error:', GraphErrorMsg(ErrCode));
readln;
exit;
end;
assign(f,'c:\1.txt');
rewrite(f);
s:= get_input(265,255); { Koordinati vvodimogo slova }
outtextxy(400, 100, s);
write(f,s);
closegraph;
close(f);
end.
Сообщение отредактировано: @^WARlock^@ -