ヨセフス問題Javaプログラム



Josephus Problem Java Programs



ヨセフスの問題を完了するためのコードを書く:N個の個人サークル、順序を並べる、次にサークルKを終了する人の数を報告したM人の個々のCountinから、次に1から始まる数を報告し続ける次の人など。オン 。出口番号を順番に印刷してください。

java.util.Scannerをインポートします
パブリッククラスOne {
public static void main(String [] args){
スキャナーsc = new Scanner( System.in )。
System.out.println( '参加者数を入力してください')
int m = sc.nextInt()
boolean [] a = new boolean [m]
System.out.println( '開始するいくつかの数字の数を入力してください')
int n = sc.nextInt()//
System.out.println( 'アウトの数を入力してください')
int k = sc.nextInt()// outs
int k1 = 0
for(int i = 0ia [i] = true //すべての仮定はありません



} int human=m n = n-1 // Since the array are numbered starting from 0, so a to reduce, such as No. 5 No. 6 position actually corresponds to the array while (human> = 1) {// if the number is greater than or equal to 1 cycle continues for(int i=ni

}

一部のc言語コード形式は異なる場合がありますが、基本的な考え方は同じです。