가위바위보

Seung jun Cha·2022년 12월 26일
0
  • A, B 두 사람이 가위바위보 게임을 합니다. 총 N번의 게임을 하여 A가 이기면 A를 출력하고, B가 이기면 B를 출력합니다. 비길 경우에는 D를 출력합니다.
    가위, 바위, 보의 정보는 1:가위, 2:바위, 3:보로 정하겠습니다.

두 사람의 각 회의 가위, 바위, 보 정보가 주어지면 각 회를 누가 이겼는지 출력하는 프로그램을 작성하세요

public class Main {
    public static void main(String[] args) {

        Main T = new Main();
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        int[] A = new int[num];
        int[] B = new int[num];
        for (int i = 0; i < num; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < num; i++) {
            B[i] = sc.nextInt();
        }

        for (int i = 0; i < num; i++) {
            System.out.println(T.solution(num, A, B));
        }
    }

    public String solution(int num, int[] A, int B[]) {

        String answer = "";
        for (int i = 0; i < num; i++) {
            if (A[i] == B[i]){
                return answer += "D";
            } else if (A[i] == 1 && B[i] == 2) {
                return answer += "B";
            } else if (A[i] == 2 && B[i] == 3) {
                return answer += "B";
            } else if (A[i] == 3 && B[i] == 1) {
                return answer += "B";
            }
            return answer +="A";
        }
        return answer;
    }
}

0개의 댓글