一道pascal编程题,帮忙解一下,最好用数组解,千恩万谢

来源:百度知道 编辑:UC知道 时间:2024/05/25 17:23:12
猴子选大王:有N只猴子围成一圈,每只猴子各一个从1到N中的依次编号,打算从中选出一个大王;经过协商,决定出选大王的规则:从第一个开始循环报数,数到M的猴子出圈,最后剩下来的就是大王。要求:从键盘输入N、M,编程计算哪一个编号的猴子成为大王( M<N<=1000 )

program sd;
const mun=50;
var
a:array[1..num] of integer;
i,p,q,t,m,n:integer;
begin
readln(n,m);
for i:=1 to n-1 do a[i]:=i+1;
a[n]:=1;
q:=n; p:=n; t:=0;
repeat
p:=a[p];
t:=t+1;
if (t mod m<>0) then q:=p
else a[q]:=a[p];
until (p:=a[p]);
writeln('The total number:',n:3);
writeln('The max number:',m:3);
writeln('The KINK is:',a[p]:3);
readln;
end.
没错的!可以照抄!

program mk;   
var a:array[1..1000]of boolean;
step,i,j,b,n,k:longint;
begin
   readln(n,step);
   fillchar(a,sizeof(a),true);
   for i:=1 to n-1 do
     begin
       b:=0;
       repeat
         inc(j);
         if j>n then j:=j m