HDACM1014
此题做法:用布尔数组的下标值来表示0~mod-1,通过其布尔值来判断一个循环是否结束,如过布尔数组的每个布尔值都为true则Good Choice,否则Bad Choice
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);while (sc.hasNext()) {int step = sc.nextInt();int mod = sc.nextInt();boolean[] boo = new boolean[mod];boo[0]=true;int a = 0;int i = 1;for (; i < boo.length; i++) {int pos = (a+step)%mod;boo[pos] = !boo[pos];a=pos;if (boo[pos]==false) {break;}}System.out.printf("%10d%10d",step,mod);if (i==boo.length) {System.out.println(" Good Choice");System.out.println();continue;}System.out.println(" Bad Choice");System.out.println();}}
}