[백준/C++] 4493 - 가위 바위 보?

orangesnail·2025년 7월 30일

백준

목록 보기
123/169

https://www.acmicpc.net/problem/4493


전체 코드

1번 참가자가 이기는 경우는 모두 하나의 조건문으로 몰아놓고, 나머지는 2번 참가자가 이기는 걸로 계산하면 구현이 쉬워진다.

#include <iostream>
using namespace std;

int main() {
    int t;
    cin >> t;

    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;

        int count1 = 0, count2 = 0;
        string winner = "";
        for (int j = 0; j < n; j++) {
            char a, b;
            cin >> a >> b;

            if (a == b) continue;
            else if ((a == 'R' &&  b == 'S') || (a == 'S' && b == 'P') || (a == 'P' && b == 'R'))
                count1++;
            else
                count2++;

        }
        if (count1 > count2) cout << "Player 1" << endl;
        else if (count1 < count2) cout << "Player 2" << endl;
        else cout << "TIE" << endl;
    }

    return 0;
}
profile
초보입니다. 피드백 환영합니다 😗

0개의 댓글