N - количество цветов.
i - глубина цвета.
N=2^i
1) 2^1=2
2) 2^2=4
3) 2^3=8
4) 2^4=16
5) 2^8=256
6) 2^16=65536
7) 2^24=16777216
Ответ: 7
Цикл выполнится два раза:
1-я итерация: a = 11 (т.к. 15 - 4 = 11)
2-я итерация: a = 7 (т.к. 11 - 4 = 7)
// PascalABC.Net 3.0, сборка 1076
var
s,ss:string;
i,n,p:integer;
begin
Write('Введите строку: '); Readln(s);
n:=Length(s); p:=Pos(',',s);
if p in [1..n-1] then begin
ss:=Copy(s,p+1,n-p);
n:=Length(ss); p:=Pos(',',ss);
if p=0 then Writeln(ss)
else Writeln(Copy(ss,1,p-1))
end
else Writeln('*** Нечего выводить ***')
end.
<u><em>Тестовые решения:</em></u>
Введите строку: 01234,45679,1011213,14151617
45679
Введите строку: 01234,45679101121314151617
45679101121314151617
Введите строку: 01234,
*** Нечего выводить ***
Uses Crt;
Const
N = 13;
Var
A:array[1..N] of integer;
i,j,Min,B:integer;
Begin
ClrScr;
Randomize;
Write('Исходный массив:');
For i:= 1 to N do
Begin
A[i]:=random(2*N+1)-N;
Write(' ',A[i])
End;
WriteLn;
Write('Отсортированный массив:');
For i:= 1 to N do
Begin
Min:=i;
For j:= i+1 to N do
if A[j] < A[Min] then Min:=j;
B:=A[i];
A[i]:=A[Min];
A[Min]:=B;
Write(' ',A[i])
End;
ReadLn
End.
{
Если что, часть программы не нужна для построения цепочки. Она просто иллюстрирует, что полученный результат верен.
}
var
sq : array[0..999] of array[0..9] of boolean;
co : array[0..999] of integer;
ar : array[1..10003] of 0..9;
i,j: integer;
x: integer;
t : boolean;
begin
for i := 0 to 999 do
begin
for j := 0 to 9 do
sq[i][j] := false;
co[i] := 0;
end;
for i := 1 to 3 do
ar[i] := 0;
i := 3;
t := true;
{write('000');}
while t do
begin
i := i + 1;
x := ar[i-3]*100 + ar[i-2]*10 + ar[i-1];
if co[x] >= 10 then t := false
else
begin
j := 1;
while sq[x][j] do
j := (j + 1) mod 10;
ar[i] := j;
sq[x][j] := true;
co[x] := co[x] + 1;
{write(j)}
end;
end;
{writeln;}
writeln('Length: ',i - 1);
{просто чтобы убедиться}
for i := 0 to 999 do
for j := 0 to 9 do
sq[i][j] := false;
t := true;
j := 0;
i := 1;
while (i <= 10000) and t do
begin
x := ar[i] * 100 + ar[i+1] * 10 + ar[i+2];
if sq[x][ar[i+3]] then t := false
else
begin
sq[x][ar[i+3]] := true;
j := j + 1;
end;
i := i + 1
end;
if t and (j = 10000) then
write('Confirmed')
<span>end.</span>