HDU2164 UVALive4065 Rock, Paper, or Scissors?【水题】

Rock, Paper, or Scissors?

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3426 Accepted Submission(s): 2163

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

Source
2007 ACM-ICPC Pacific Northwest Region

问题链接HDU2164 UVALive4065 Rock, Paper, or Scissors?
问题简述:(略)
问题分析
    水题,不解释。需要注意代码写得更加简洁。
程序说明
    用输入格式"%*c"跳过空格。格式"%c"不会跳过空白符。
参考链接:(略)
题记:(略)

扫描二维码关注公众号,回复: 4804613 查看本文章

AC的C语言程序如下:

/* HDU2164 UVALive4065 Rock, Paper, or Scissors? */

#include <stdio.h>

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

int main(void)
{
    int t, n;
    char a, b;
    scanf("%d", &t);
    while(t--) {
        scanf("%d%*c", &n);
        int asum = 0, bsum = 0;
        while(n--) {
            scanf("%c %c%*c", &a, &b);
            asum += judge(a, b);
            bsum += judge(b, a);
        }

        if(asum > bsum)
            printf("Player 1\n");
        else if(asum == bsum)
            printf("TIE\n");
        else
            printf("Player 2\n");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10229749.html