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?的更多相关文章

  1. HDU 2164 Rock, Paper, or Scissors?

    http://acm.hdu.edu.cn/showproblem.php?pid=2164 Problem Description Rock, Paper, Scissors is a two pl ...

  2. HDU 2164(模拟)

    Rock, Paper, or Scissors? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  4. HDOJ(HDU).1412 {A} + {B} (STL SET)

    HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...

  5. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  6. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  7. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  8. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  9. HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)

    HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的 ...

随机推荐

  1. strut2.xml中result param详细设置

    1.Struts2.xml配置文件: 2.Jsp中:说明回调函数一个参数即可.把上面的俩个参数msg和page封装到一起了 3.msg是Action中全局变量 可参考:http://qiaolevip ...

  2. MySQL命令行下查看运行状态

    查看MySQL的运行状态用命令行的show语句show status是查看MySQL运行情况,和上面那种通过pma查看到的信息基本类似. show variables是查看MySQL的配置参数,还可以 ...

  3. Xcode升后插件失效

    Xcode升后插件失效,与添加插件不小心点击Skip Bundle解决办法 字数267 阅读4731 评论1 喜欢12 今天升级了xcode到6.4 发现之前装的插件不能使用了.这里有一个解决的方案: ...

  4. 浅谈angular框架

    最近新接触了一个js框架angular,这个框架有着诸多特性,最为核心的是:MVVM.模块化.自动化双向数据绑定.语义化标签.依赖注入,以上这些全部都是属于angular特性,虽然说它的功能十分的强大 ...

  5. 『重构--改善既有代码的设计』读书笔记----Substitute Algorithm

    重构可以把复杂的东西分解成一个个简单的小块.但有时候,你必须壮士断腕删掉整个算法,用简单的算法来取代,如果你发现做一件事情可以有更清晰的方式,那你完全有理由用更清晰的方式来解决问题.如果你开始使用程序 ...

  6. Linux下ln链接命令详解

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个不同的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件. 当我们需要在不同的目录,用到相同的 ...

  7. GRUB配置

    参数讲解: default :定义缺省启动的系统 如果安装多系统的话 会有多个title 信息 可以通过设置 default: 来改变启动那个系统 默认第一个为0 第二个为1 依次类推 timeout ...

  8. IOS 命令行安装备忘

    1. 首先要越狱 2. 新增BIGBOSS或者苹果核的源 3. 安装MobileTerminal和MobileTerm Backgrounder (用于后台运行命令),最好r520以上版本,R530还 ...

  9. HTML部分标签的含义

    标签的用途:我们学习网页制作时,常常会听到一个词,语义化.那么什么叫做语义化呢,说的通俗点就是:明白每个标签的用途(在什么情况下使用此标签合理)比如,网页上的文章的标题就可以用标题标签,网页上的各个栏 ...

  10. Josephus

    利用循环链表模拟约瑟夫问题,把自杀的人的顺序排列出来 代码如下: #include<stdio.h> #include<stdlib.h> typedef int status ...