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 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");
}
}
}
}
HDOJ(HDU) 2164 Rock, Paper, or Scissors?的更多相关文章
- HDU 2164 Rock, Paper, or Scissors?
http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...
- HDU 2164(模拟)
Rock, Paper, or Scissors? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
- HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)
HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的 ...
随机推荐
- alpha属性设置
alpha是来设置透明度的,它的基本属性是filter:alpha(opacity,finishopacity,style,startX,startY,finishX,finishY).opacity ...
- 在线预览文件(pdf)
1.flash版(借助flexpaper工具) 可以把pdf文件用pdf2swf工具转换成swf文件.下载地址http://www.swftools.org/download.html 转换代码如下: ...
- vim字符串替换
vi/vim 中可以使用 :s 命令来替换字符串.以前只会使用一种格式来全文替换,今天发现该命令有很多种写法(vi 真是强大啊,还有很多需要学习),记录几种在此,方便以后查询. :s/vivian/s ...
- dnw for linux: Ubuntu下可用,无需编译驱动,mini2440可用
1.安装所需库文件 sudo apt-get install libusb-dev 2.源代码如下 /* dnw2 linux main file. This depends on libusb. * ...
- PHP 开发API接口 注册,登录,查询用户资料
服务端 <?php require 'conn.php'; header('Content-Type:text/html;charset=utf-8'); $action = $_GET['ac ...
- angular.js 字符串
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...
- SpringMVC4+thymeleaf3的一个简单实例(篇三:页面参数获取)
本篇将通过示例介绍页面参数是如何传递到后台的.我们继续沿用之前搭好的程序结构,如果你不知道,请参照前两篇.为方便跳转页面,我们在首页以及zoolist.html页面都加上彼此地址的链接:首页: zoo ...
- Java反射与代理
Java反射机制与动态代理,使得Java更加强大,Spring核心概念IoC.AOP就是通过反射机制与动态代理实现的. 1 Java反射 示例: User user = new User( ...
- 赋值,copy和deepcopy
python的复制,拷贝,和深拷贝. >>> a=[23,3]>>> b=a>>> b.append(234)>>> a[23, ...
- Python直接迭代序列比通过索引迭代序列快。
小脚本跑一下看看时间. 原理:直接迭代序列是通过Python内置的迭代器去实现的,而如果迭代序列需要先造一个可迭代的序列出来.内置的迭代器并不是一下将所有的数据放入内存中,而是需要多少取多少. #!/ ...