var
n, Num, i, j, t: integer;
Count: array[1..12] of integer;
Names: array[1..12] of integer;
begin
for i := 1 to 12 do
begin
Count[i] := 0;
Names[i] := i;
end;
ReadLn(N); { Считываем количество запросов}
for i := 1 to N do
begin
ReadLn(t); {считали очередной запрос}
Count[t] := Count[t] + 1;
end;
{Сортируем массивы Names и Count в порядке убывания значений массива Count}
for i := 12 downto 2 do
for j := 2 to i do
if Count[j - 1] < Count[j] then
begin
t := Count[j];
Count[j] := Count[j - 1];
Count[j - 1] := t;
t := Names[j];
Names[j] := Names[j - 1];
Names[j - 1] := t;
end;
for i := 12 downto 1 do
if Count[i] > 0 then
WriteLn(Names[i], ' ', Count[i]);
end.
Объяснение:
chislo: string;
begin
chislo:='12323';
for j:=1 to 14 do
begin
i:=1;
while i<=length(chislo) do
begin
if copy(chislo,i,1)='1' then begin delete(chislo,i,1);insert('33',chislo,i); inc(i); end;
inc(i);
end;
i:=1;
while i<=length(chislo) do
begin
if copy(chislo,i,1)='2' then begin delete(chislo,i,1);insert('1',chislo,i); end;
inc(i);
end;
i:=1;
while i<=length(chislo) do
begin
if copy(chislo,i,1)='3' then begin delete(chislo,i,1);insert('2',chislo,i); end;
inc(i);
end;
end;
Writeln(chislo);
readln;
end.