HDU 2164 Rock, Paper, or Scissors?

http://acm.hdu.edu.cn/showproblem.php?pid=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 <bits/stdc++.h>
using namespace std;

char p1[1111], p2[1111];

int cmp(char a, char b) {

    if(a == ‘S‘) {
        if(b == ‘P‘) return 2;
        if(b == ‘R‘) return 1;
    }

    if(a == ‘R‘) {
        if(b == ‘S‘) return 2;
        if(b == ‘P‘) return 1;
    }

    if(a == ‘P‘) {
        if(b == ‘R‘) return 2;
        if(b == ‘S‘) return 1;
    }
}

int main() {
    int T;
    scanf("%d", &T);
    while(T --) {
        int x;
        scanf("%d", &x);
        int cnt = 0, ans = 0;
        getchar();
        for(int i = 1; i <= x; i ++) {
            scanf("%c %c", &p1[i], &p2[i]);
            getchar();
            if(cmp(p1[i], p2[i]) == 2)
                cnt ++;
            else if(cmp(p1[i], p2[i]) == 1)
                ans ++;
        }

        if(cnt > ans)
            printf("Player 1\n");
        else if(cnt == ans)
            printf("TIE\n");
        else
            printf("Player 2\n");
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9417374.html

时间: 2024-12-18 15:09:54

HDU 2164 Rock, Paper, or Scissors?的相关文章

HDOJ(HDU) 2164 Rock, Paper, or Scissors?

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 w

HDU 2164(模拟)

Rock, Paper, or Scissors? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2927    Accepted Submission(s): 1873 Problem Description Rock, Paper, Scissors is a two player game, where each player s

SDUT 3568 Rock Paper Scissors 状压统计

就是改成把一个字符串改成三进制状压,然后分成前5位,后5位统计, 然后直接统计 f[i][j][k]代表,后5局状压为k的,前5局比和j状态比输了5局的有多少个人 复杂度是O(T*30000*25*m)m比较小,也就最多几十吧,将将过 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cstdlib> #include &

GYM 101667H Rock Paper Scissors(FFT)

题意:给你一个串a,是有R,S,P(石头剪刀布)构成的,然后还有一个序列b是你的出牌顺序,但你可以跳过机器的前x个出牌,从x+1开始出,问你最多赢几次 思路:好烦啊,这个题下午一直不会做,感觉和之前学弟将的一个模糊匹配的很像,但好像也不怎么像,挂机一下午. 这个题其实是利用了卷积的性质,我们先考虑单独的每一个字母,因为我们在卷积的时候不能牵扯其他的字符,如果有其他的字符,就类似于模糊匹配了,那是我们只是用FFT加速多项式乘法,而这道题的FFT其实是用FFT算出对于(FFT后的)第i个位置,我们字

HDU 5882 Balanced Game

Balanced Game Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 508    Accepted Submission(s): 428 Problem Description Rock-paper-scissors is a zero-sum hand game usually played between two people

hdu 4115 Eliminate the Conflict

Description Conflicts are everywhere in the world, from the young to the elderly, from families to countries. Conflicts cause quarrels, fights or even wars. How wonderful the world will be if all conflicts can be eliminated.Edward contributes his lif

Eliminate the Conflict HDU - 4115

Conflicts are everywhere in the world, from the young to the elderly, from families to countries. Conflicts cause quarrels, fights or even wars. How wonderful the world will be if all conflicts can be eliminated. Edward contributes his lifetime to in

Rock-Paper-Scissors Tournament[HDU1148]

Rock-Paper-Scissors TournamentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2178 Accepted Submission(s): 693 Problem DescriptionRock-Paper-Scissors is game for two players, A and B, who each choo

2016 ACM/ICPC Asia Regional Qingdao Online 1005 Balanced Game

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each pl