История изменений
Исправление bormant, (текущая версия) :
Будем есть слона частями...
Чтение и вывод исходных:
const nmax=10;
type TLine = array [0..25] of Char;
var
a: array [1..nmax] of Char;
n: Integer;
begin
Assign(input,'in.txt'); Reset(input);
Assign(output,'result.txt'); Rewrite(output);
{n:=0;}
while (n<nmax) and not EoF do begin
ReadLn(a[n]); WriteLn(a[n]);
end;
{...}
Close(input); Close(output);
end.
Сравнение:
function IsLess(const a, b: TLine): Boolean;
var j: Integer;
begin
IsLess:=False;
for j:=16 to 24 do
if a<b then begin
IsLess:=True; Exit;
end else if a>b then Exit;
end;
Сортировка и вывод результата:
var
t: TLine;
i, j: Integer;
...
for i:=2 to n do begin
t:=a[i]; j:=i;
while (j>1) and IsLess(t,a[j-1]) do begin
a[j]:=a[j-1]; Dec(j);
end;
a[j]:=t;
end;
WriteLn; WriteLn('Sorted:');
for i:=1 to n do WriteLn(a[i]);
Исходная версия bormant, :
Будем есть слона частями...
Чтение:
const nmax=10;
type TLine = array [0..25] of Char;
var
a: array [1..nmax] of Char;
n: Integer;
begin
Assign(input,'in.txt'); Reset(input);
Assign(output,'result.txt'); Rewrite(output);
{n:=0;}
while (n<nmax) and not EoF do begin
ReadLn(a[n]); WriteLn(a[n]);
end;
{...}
Close(input); Close(output);
end.
Сравнение:
function IsLess(const a, b: TLine): Boolean;
var j: Integer;
begin
IsLess:=False;
for j:=16 to 24 do
if a<b then begin
IsLess:=True; Exit;
end else if a>b then Exit;
end;
Сортировка:
var
t: TLine;
i, j: Integer;
...
for i:=2 to n do begin
t:=a[i]; j:=i;
while (j>1) and IsLess(t,a[j-1]) do begin
a[j]:=a[j-1]; Dec(j);
end;
a[j]:=t;
end;
WriteLn; WriteLn('Sorted:');
for i:=1 to n do WriteLn(a[i]);