Subscribed unsubscribe Subscribe Subscribe

yukicoder No.88 次はどっちだ

Problem

No.88 次はどっちだ - yukicoder

Solution

これまで置いた石の数を調べる。その数が偶数なら先手、奇数なら後手。

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String S = reader.readLine();
        int turn = 0;
        for (int i = 0; i < 8; i++) {
            char[] row = reader.readLine().toCharArray();
            for (int j = 0; j < 8; j++) {
                if (row[j] != '.') {
                    turn += 1;
                }
            }
        }
        if (turn % 2 == 0) {
            System.out.println(S);
        } else {
            System.out.println(anotherPlayer(S));
        }
    }

    private static String anotherPlayer(String player) {
        if (player.equals("oda")) {
            return "yukiko";
        } else {
            return "oda";
        }
    }

}
Remove all ads