Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 4593번 Rock, Paper, Scissors 본문

YJ/C++

[백준/BOJ/C++] 4593번 Rock, Paper, Scissors

Team DAON 2021. 11. 2. 17:27

[문제]

Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a fist (rock), open hand (paper), or two-finger V (scissors). If both players show the same gesture, they try again. They continue until there are two different gestures. The winner is then determined according to the table below:

Rock beats Scissors
Paper beats Rock
Scissors beats Paper

Your task is to take a list of symbols representing the gestures of two players and determine how many games each player wins.

In the following example:

Turn     : 1 2 3 4 5
Player 1 : R R S R S
Player 2 : S R S P S

Player 1 wins at Turn 1 (Rock beats Scissors), Player 2 wins at Turn 4 (Paper beats Rock), and all the other turns are ties.

[입력]

The input contains between 1 and 20 pairs of lines, the first for Player 1 and the second for Player 2. Both player lines contain the same number of symbols from the set {'R', 'P', 'S'}.  The number of symbols per line is between 1 and 75, inclusive.  A pair of lines each containing the single character 'E' signifies the end of the input.

[출력]

For each pair of input lines, output a pair of output lines as shown in the sample output, indicating the number of games won by each player.

[Source Code]

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main() {
	while(true){
		string p1, p2;
		int score1 = 0, score2 = 0;
		cin >> p1 >> p2;
		if(p1 == "E" && p2 == "E") break;

		for(int i = 0; i < p1.length(); i++){
			if(p1[i] == 'R'){
				if(p2[i] == 'S') score1++;
				else if(p2[i] == 'P') score2++;
			}
			else if(p1[i] == 'S'){
				if(p2[i] == 'R') score2++;
				else if(p2[i] == 'P') score1++;
			}
			else if(p1[i] == 'P'){
				if(p2[i] == 'S') score2++;
				else if(p2[i] == 'R') score1++;
			}
		}

		cout << "P1: " << score1 << "\n";
		cout << "P2: " << score2 << "\n";
	}
}

[결과 화면]

'YJ > C++' 카테고리의 다른 글

[백준/BOJ/C++] 13771번 Presents  (0) 2021.11.02
[백준/BOJ/C++] 12517번 Centauri Prime (Small1)  (0) 2021.11.02
[백준/BOJ/C++] 7581번 Cuboids  (0) 2021.11.02
[백준/BOJ/C++] 5751번 Head or Tail  (0) 2021.11.02
[백준/BOJ/C++] 9699번 RICE SACK  (0) 2021.11.02