POJ3917 UVALive4575 Rock, Paper, Scissors【水题】

Rock, Paper, Scissors
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1722 Accepted: 1069

Description

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.

Input

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.

Output

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.

Sample Input

RRSRS
SRSPS
PPP
SSS
SPPSRR
PSPSRS
E
E

Sample Output

P1: 1
P2: 1
P1: 0
P2: 3
P1: 2
P2: 1

Source

Mid-Central USA 2009

问题链接POJ3917 UVALive4575 Rock, Paper, Scissors
问题简述:(略)
问题分析
    石头剪刀布问题,输出每个人胜场数量。水题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* POJ3917 UVALive4575 Rock, Paper, Scissors */

#include <stdio.h>

#define N 75
char s1[N + 1], s2[N+1];

int judge(char a, char b)
{
   return (a == 'R' && b == 'S') || (a == 'S' && b == 'P') || (a == 'P' && b == 'R');
}

int main(void)
{
    int cnt1, cnt2, i;
    while(scanf("%s%s", s1, s2) != EOF && s1[0] != 'E') {
        cnt1 = cnt2 = 0;
        for(i = 0; s1[i]; i++) {
            cnt1 += judge(s1[i], s2[i]);
            cnt2 += judge(s2[i], s1[i]);
        }

                printf("P1: %d\nP2: %d\n", cnt1, cnt2);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/tigerisland45/article/details/86060233