Who does not love to play cards in Java

Who does not love to play cards

[Problem Description]
BobLee recent review study section, but he also likes to play cards (Who does not love to play cards it?). But as a ACMER, Landlords obviously can not satisfy his interest,
so he came out and YYD YY with the rules of a game, the rules are as follows.
1, a total of n cards;
2, the two sides take turns drawing cards;
3, the number of cards per person per catch only the power of 2 (ie: 1,2,4,8,16 ...)
4, grasping finish brand, the outcome of the results came out: the last complete grasp of man-made card winner;
BobLee and YYD are very smart people, to tell you the number of cards now, you tell me who will win? BobLee acquire.

[INPUT]
input multiple rows, each row is the card number n (1 <= n <= 1000)

[Output]
If BobLee win, BobLee output, otherwise the output YYD, each row

[Sample input]
3

[Sample output]
BobLee
YYD
PS:
we can find a rule, in addition to 1 than to take each number can only be a multiple of 2, so that,
each time to take the number 3 is to take more than 2
lead as long as a multiple of three after victory will take
an example: n = 9
first take 8, take 1 second, the second victory
of a fetch 4, take 1 second, to take a first, two 1, a 1, two 1, the second victory
. . .
Slowly reasoning can own,
as long as a multiple of three, after holding will win
the following code

package 第二次模拟;

import java.util.Scanner;

public class Demo8谁不爱打牌 {
	private static Scanner sc;
	private static int n;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		while(sc.hasNext()) {
			n = sc.nextInt();
			if(0 == n % 3) {
				System.out.println("YYD");
			} else {
				System.out.println("BobLee");
			}
		}
		sc.close();
	}

}

发布了1313 篇原创文章 · 获赞 1万+ · 访问量 102万+

Guess you like

Origin blog.csdn.net/a1439775520/article/details/104497258