Перевести код с Pascal на C++ - вопрос №3551206

Const n=20;
mas:array[1..n] of integer=( 25,57,25,25,3,74,21,83,8,47,18,91,2,85,16,48,53,1,88,10);
Var a,aBest:array[1..n] of integer;
i,dm:integer;


Procedure Perebor(k:integer);
Var i,p:integer;
begin
If k>n then begin
p:=0;
For i:=1 to n do
If a[i]=1 then p:=p+mas[i];
If p>600 then Exit;
If (a[11]=0) or (a[12]=0) or (a[13]=0) or (a[14]=0) or (a[15]=0) then Exit;
If dm>(600-p) then begin
dm:=600-p;
aBest:=a
end;
Exit
end;
For i:=0 to 1 do begin
a[k]:=i;
Perebor(k+1)
end
end;

begin
dm:=1000000;
Perebor(1);
Writeln('dm=',dm);
for i:=1 to n do Write(aBest[i])
end.
Вопрос задан анонимно
09.12.19
0 ответов
Ответов пока нет

Еva

от 100 p.
Читать ответы
Посмотреть всех экспертов из раздела Учеба и наука > Информатика
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store