主题:猴子选大王 经典问题
const number=3;
var n,num,i,total:integer;
a:array[1..100]of boolean; order:boolean;
begin
writeln('input n:');
readln(n);
total:=n;
for i:=1 to n do a[i]:=true;
repeat
order:=true;
num:=0;
for i:=1 to n do
if a[i] then begin
num:=num+1;
if (num=number) then begin
a[i]:=false;total:=total-1;
num:=0;
end;
end;
if total>number-1 then order:=false;
num:=0;
for i:=n downto 1 do
if a[i] then begin
num:=num+1;
if (num=number) then begin
a[i]:=false;total:=total-1;
num:=0;
end;
end;
until total=number-1;
if not order then for i:=1 to n do if a[i] then begin
writeln('The Monkey King is :',i);readln;halt;end;
if order then for i:=n downto 1 do if a[i] then begin
writeln('The Monkey King is :',i);readln;
end;
end.
var n,num,i,total:integer;
a:array[1..100]of boolean; order:boolean;
begin
writeln('input n:');
readln(n);
total:=n;
for i:=1 to n do a[i]:=true;
repeat
order:=true;
num:=0;
for i:=1 to n do
if a[i] then begin
num:=num+1;
if (num=number) then begin
a[i]:=false;total:=total-1;
num:=0;
end;
end;
if total>number-1 then order:=false;
num:=0;
for i:=n downto 1 do
if a[i] then begin
num:=num+1;
if (num=number) then begin
a[i]:=false;total:=total-1;
num:=0;
end;
end;
until total=number-1;
if not order then for i:=1 to n do if a[i] then begin
writeln('The Monkey King is :',i);readln;halt;end;
if order then for i:=n downto 1 do if a[i] then begin
writeln('The Monkey King is :',i);readln;
end;
end.