Monkey Choose King Question Answer

xiaoxiao2021-03-05  39

There are twenty monkeys to enclose a circle and start from scratch. Who is the king?

Delphi Solution:

Procedure TForm1.Button1Click (Sender: Tobject); VAR KK, MM, II: Integer; var_aa: array [1..20] of integer; begin var_aa [1]: = 1; for ii: = 2 to 20 do var_aa [ II]: = 0; KK: = 0; II: = 1; mm: = 20; While (1 = 1) DO Begin KK: = KK 1; II <20 THEN II: = II 1 ELSE II: = 1; WHILE (var_aa [ii] = 1) DO Begin II: = II 1; IF II> 20 THEN II: = 1; END; if Kk MOD 3 = 0 THEN BEGIN VAR_AA [II]: = 1; mm : = MM-1; End; IF mm = 1 Then Break; end; for ii: = 1 to 20 do if var_aa [ii] = 0 THEN BEGIN SHOWMESAGE (INTTOSTR (II)); // Break; End;

转载请注明原文地址:https://www.9cbs.com/read-32214.html

New Post(0)