Мой массив целых чисел:
AR: array [0..5] of integer = (6, 5, 4, 8, 9, 7);
Алгоритм:
Take the first value of the AR array (6)
Find the first great value that comes after it (9)
Find out how ahead you are after yourself (4)
write this as the first value in the result array
....
Get the second value in the AR index (5)
The first great value after him (9)
Find out how ahead you are after yourself (3)
write 3 after 4 in our results series.
.
.
Этот процесс будет повторяться для каждой записи массива. Если значения не превышают следующих значений, будет записано '0'
. Последнее значение должно быть '0'
.
Ожидаемый результат должен быть:
OutValue = 4-3-2-1-0-0
У меня нет кодов, которые действительно работают.
const
AR:array [0..5] of integer = (6, 5, 4, 8, 9, 7)
var
S:Tstringlist;
output:string;
i,j,g,n:integer;
begin
S:=Tstringlist.create;
for i:=0 to 5 do
for j:=i+1 to 5 do begin
if AR[i] > AR[j] then begin
g:=0;
AR[i]:=AR[j];
AR[i]:=g;
S.add( inttostr(g));
end
else if AR[i] < AR[j] then
begin
g:=sizeof(maxintvalue(AR[i]));
AR[i]:=AR[j];
AR[i]:=g;
S.add( inttostr(g));
end;
end;
For i:=0 to 5 do
begin
//S.Sorted:=true;
output:=S.Text;
end;
S.free;
writeln(output);
readln;
end.
Спасибо.