Rock, Paper, or Scissors? 2164
来源:互联网 发布:大数据开发 编辑:程序博客网 时间:2024/05/17 04:56
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;}
- Rock, Paper, or Scissors? 2164
- hdu 2164 Rock, Paper, or Scissors?
- JAVA hdu 2164 Rock, Paper, or Scissors?
- HDOJ(HDU) 2164 Rock, Paper, or Scissors?
- HDOJ 2164 Rock, Paper, or Scissors?(水题)
- HDU2164:Rock, Paper, or Scissors?
- 杭电acm-2164 Rock, Paper, or Scissors?
- 1407281127-hd-Rock, Paper, or Scissors.cpp
- HDU2164 Rock, Paper, or Scissors?【水题】
- Rock-Paper-Scissors
- 【poj2339】Rock, Scissors, Paper
- Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ 2339 Rock, Scissors, Paper
- poj 3917 Rock, Paper, Scissors
- POJ-2339-Rock, Scissors, Paper
- poj 2339 Rock, Scissors, Paper
- POJ - 2339 Rock, Scissors, Paper
- 关于C语言头文件的一些认识
- C语言头文件作用及写法
- 关于在linux系统上安装vpn(pptp)服务器
- 安卓Android系统超级终端(终端模拟…
- Ubuntu下如何在桌面创建一个桌面快捷方式
- Rock, Paper, or Scissors? 2164
- Android IPC编程简介
- linux 编码转换
- 最大的划分
- linux查找文件内容的命令
- 解决 Eclipse项目红感叹号(或×号)
- Android高手进阶
- c++之this指针做参数实现对象间的交互实例
- 存储过程的入门使用