L1-4 稳赢 (15分)

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

现要求你编写一个稳赢不输的程序,根据对方的出招,给出对应的赢招。但是!为了不让对方输得太惨,你需要每隔KKK次就让一个平局。

输入格式:

输入首先在第一行给出正整数KKK≤10\le 1010),即平局间隔的次数。随后每行给出对方的一次出招:ChuiZi代表“锤子”、JianDao代表“剪刀”、Bu代表“布”。End代表输入结束,这一行不要作为出招处理。

输出格式:

对每一个输入的出招,按要求输出稳赢或平局的招式。每招占一行。

输入样例:

2
ChuiZi
JianDao
Bu
JianDao
Bu
ChuiZi
ChuiZi
End

    
    

输出样例:

Bu
ChuiZi
Bu
ChuiZi
JianDao
ChuiZi
Bu

    
    
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

//** Class for buffered reading int and double values *//*
class Reader {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	// ** call this method to initialize reader for InputStream *//*
	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	// ** get next word *//*
	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			// TODO add check for eof if necessary
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static boolean hasNext()throws IOException {
		return tokenizer.hasMoreTokens();
	}
	static String nextLine() throws IOException{
		return reader.readLine();
	}
	static char nextChar() throws IOException{
		return next().charAt(0);
	}
	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static float nextFloat() throws IOException {
		return Float.parseFloat(next());
	}
}
public class Main {

	public static void main(String[] args) throws IOException {
		Reader.init(System.in);
		int n = Reader.nextInt();
		int number = 0;
		while (true) {
			String s = Reader.next();			
			if (s.equals("ChuiZi")) {
				if (number==n) {
					System.out.println("ChuiZi");
					number = -1;
				}else {
					System.out.println("Bu");
				}
			}else if(s.equals("JianDao")) {
				if (number==n) {
					System.out.println("JianDao");
					number = -1;
				}else {
					System.out.println("ChuiZi");
				}
			}else if(s.equals("Bu")) {
				if (number==n) {
					System.out.println("Bu");
					number = -1;
				}else {
					System.out.println("JianDao");
				}
			}else if(s.equals("End")) {
				break;
			}
			number++;
		}
	}
}



发布了45 篇原创文章 · 获赞 8 · 访问量 1770

猜你喜欢

转载自blog.csdn.net/weixin_43888039/article/details/104108354