首页 > 代码库 > Pascal约瑟夫问题

Pascal约瑟夫问题

 1 program Project2;
 2 
 3 {$APPTYPE CONSOLE}
 4 const
 5 n=13;
 6 m=5;
 7 
 8 
 9 
10   Type
11   peopleno= array[1..n] of integer;
12 
13 var
14   datering:peopleno;
15   s,p,i:integer;
16   flag:boolean;
17 
18 begin
19   { TODO -oUser -cConsole Main : Insert code here }
20   for i:=1 to n do datering[i]:=1;
21   s:=0;{用于报数};
22   p:=0;{出圈人数};
23   flag:=true;
24   while flag = true do
25   for i:=1 to n do
26   begin
27    s:=s + datering[i];
28    if s=m then
29    begin
30    s:=0;
31    datering[i]:=0;
32    p:=p + 1;
33    writeln(p=,p,i:4);
34    if p=n then flag:=false;{当flag=false时,表示圈中无人};
35    end;
36    end;
37    readln;
38 end.

 

Pascal约瑟夫问题