1019:石头剪刀布

1.题目:

题目描述

现在有两个人在玩石头剪子布游戏,请你判断最后谁赢了。
用R代表石头,S代表剪子,P代表布。


 

输入格式

输入的第一行是一个整数t(0<t<1000),表示测试样例的数目。
每组输入样例的第一行是一个整数n(0<n<100),表示游戏次数。
接下来n行,每行由两个字母组成,两个字母之间用一个空格分隔,这些字母只会是R,S或P。
第一个字母表示Player1的选择,第二个字母表示Player2的选择。


 

输出

对于每组输入样例,输出获胜方的名字(Player1或Player2),如果平均,则输出TIE。

 

样例输入

3
2
R P
S R
3
P P
R S
S R
1
P R

 

样例输出

Player 2
TIE
Player 1

 

2.代码一:

 

#include <iostream>
using namespace std;

int main()
{
    int t, n, score1, score2;
    char a, b;

    cin >> t;

    while (t--) {
        cin >> n;

        score1 = score2 = 0;

        while (n--) {
                
            cin >> a >> b;

            if (a == b) {
                score1++;
                score2++;
            } else if (a == 'R' && b == 'S')
                score1++;
            else if (a == 'S' && b == 'R')
                score2++;
            else if (a == 'P' && b == 'R')
                score1++;
            else if (a == 'R' && b == 'P')
                score2++;
            else if (a == 'S' && b == 'P')
                score1++;
            else if (a == 'P' && b == 'S')
                score2++;
                
        }

        if (score1 > score2)
            cout << "Player 1";
        else if (score1 == score2)
            cout << "TIE";
        else if (score1 < score2)
            cout << "Player 2";

        cout << endl;
    }

    return 0;
}


 

 

代码二:

 

#include<stdio.h>

int main()
{
    int t, n, s1, s2;
    char a, b;

    scanf("%d", &t);

    while (t--) {
        scanf("%d%*c", &n);

        s1 = s2 = 0;

        while (n--) {
            scanf("%c %c%*c", &a, &b);

            if ((a == 'R' && b == 'S') || (a == 'S' && b == 'P') || (a == 'P' && b == 'R'))
                s1++;
            else if ((b == 'R' && a == 'S') || (b == 'S' && a == 'P') || (b == 'P' && a == 'R'))
                s2++;
            else {
                s1++;
                s2++;
            }
        }

        if (s1 > s2)
            printf("Player 1\n");
        else if (s1 < s2)
            printf("Player 2\n");
        else
            printf("TIE\n");
    }

    return 0;
}


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值