Rock, Paper, or Scissors? 2164

Problem Description

Rock, Paper, Scissors is a two player game, where each player simultaneously chooses one of the 

three items after counting to three. The game typically lasts a pre-determined number of rounds. 

The player who wins the most rounds wins the game. Given the number of rounds the players will 

compete, it is your job to determine which player wins after those rounds have been played.

The rules for what item wins are as follows:

?Rock always beats Scissors (Rock crushes Scissors)
?Scissors always beat Paper (Scissors cut Paper)
?Paper always beats Rock (Paper covers Rock)

Input

The first value in the input file will be an integer t (0 < t < 1000) representing the number of test 

cases in the input file. Following this, on a case by case basis, will be an integer n (0 < n < 100) 

specifying the number of rounds of Rock, Paper, Scissors played. Next will be n lines, each with 

either a capital R, P, or S, followed by a space, followed by a capital R, P, or S, followed by a 

newline. The first letter is Player 1抯 choice; the second letter is Player 2抯 choice.

Output

For each test case, report the name of the player (Player 1 or Player 2) that wins the game, 

followed by a newline. If the game ends up in a tie, print TIE.

Sample Input

3

2

R P

S R

3

P P

R S

S R

1

P R

Sample Output

Player 2

TIE

Player 1

#include <cstdio>

int main(int argc, const char* argv[])
{
    int nCases = 0;
    scanf("%d", &nCases);
    while (nCases--)
    {
        int nRounds = 0;
        scanf("%d", &nRounds);
        getchar();
        char ch1, ch2;
        int n1 = 0, n2 = 0;
        for (int i=0; i<nRounds; ++i)
        {
            scanf("%c %c", &ch1, &ch2);
            getchar();
            if ((ch1 == 'R' && ch2 == 'S')
                || ch1 == 'P' && ch2 == 'R'
                || ch1 == 'S' && ch2 == 'P')
            {
                ++n1;
            }
            else if (ch1 != ch2)
            {
                ++n2;
            }
        }

        if (n1 == n2)
        {
            printf("TIE\n");
        }
        else if (n1 > n2)
        {
            printf("Player 1\n");
        }
        else if (n1 < n2)
        {
            printf("Player 2\n");
        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值