HDOJ(HDU) 2164 Rock, Paper, or Scissors?
2016-05-05 19:52
567 查看
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
题意:
R代表石头,S代表剪刀,P代表纸,就是剪刀石头布的规则。
第一个字符是人1出的,第二个字符是人2出的。
判断最后是谁胜利。(赢的次数多的胜利)
人一胜利就输出:Player 1
平局就输出:TIE
人二胜利就输出:Player 2
Java不能从终端读取单个字符(char型)。这个有点不好。。。。得自己转换。。
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
题意:
R代表石头,S代表剪刀,P代表纸,就是剪刀石头布的规则。
第一个字符是人1出的,第二个字符是人2出的。
判断最后是谁胜利。(赢的次数多的胜利)
人一胜利就输出:Player 1
平局就输出:TIE
人二胜利就输出:Player 2
Java不能从终端读取单个字符(char型)。这个有点不好。。。。得自己转换。。
import java.util.Scanner; public class Main{ public static void main(String[] args) { String strs1[] = {"RS","SP","PR"}; String strs2[] = {"SR","PS","RP"}; Scanner sc = new Scanner(System.in); int t =sc.nextInt(); while(t-->0){ int n = sc.nextInt(); int p1=0; int p2=0; String str1=null; String str2=null; String str=null; for(int i=0;i<n;i++){ str1 = sc.next(); str2 = sc.next(); if(str1.equals(str2)){ continue; } boolean isStr1=false; str=str1+str2; for(int j=0;j<strs1.length;j++){ if(str.equals(strs1[j])){ p1++; isStr1=true; break; } } if(isStr1) continue; for(int j=0;j<strs2.length;j++){ if(str.equals(strs2[j])){ p2++; break; } } } if(p1>p2){ System.out.println("Player 1"); }else if(p1<p2){ System.out.println("Player 2"); }else{ System.out.println("TIE"); } } } }
相关文章推荐
- hadoop正式学习之redis---网络数据爬虫
- 判断一个字符串中所有子串是否为回文子串
- PHP设计模式之单例模式
- 理工贪心独木舟上的旅行
- 数据库--并发控制
- 3. Android框架和工具之 xUtils(BitmapUtils)
- Leetcode 17. Letter Combinations of a Phone Number
- Activity和Fragment传递数据的两种方式
- php+mysql+apache的安装与配置
- 自定义View-6 状态按钮 滑动 点击
- 多态
- iOS开发技巧系列---打造强大的BaseModel
- 第十周项目四 警察和厨师(1)
- Redis实际应用场景
- linux下目录结构与常用命令
- ASP.NET简介
- POJ 2375 Cow Ski Area 增加最小边使图强连通
- java文件输入输出流
- 开源项目共享平台推荐
- 心血来潮 写一篇关于python list 的用法