Hdoj (HDU) 2164 Rock, Paper, or Scissors?

Source: Internet
Author: User
Tags rounds

Problem Description
Rock, Paper, Scissors is a-a-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 wins the most rounds wins the game. Given the number of rounds the players would compete, it's your job to determine which player wins after those rounds has been played.

The rules for what item WINS is 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 would be a integer t (0 < T < representing) the number of test cases in the I Nput file. Following this, in a case by case basis, would be an integer n (0 < n <) specifying the number of rounds of Rock, Paper, Scissors played. Next'll be n lines, each with either a capital R, p, or S, followed by a space, followed by a capital R, p, or S, follow Ed by a newline. The first letter is Player 1 world抯 choice; The second is Player 2 world抯 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
Rs
S R
1
P R

Sample Output
Player 2
TIE
Player 1

Test instructions
R for Stone, s for scissors, p for paper, the rules for scissors and stone cloth.
The first character is the person 1 out, the second character is the person 2 out.
Judge who wins in the end. (Win a lot of wins)
One victory on the output: Player 1
Draw on output: tie
Man two wins on output: Player 2

Java cannot read a single character (char type) from a terminal. This is a little bit bad .... Have to convert yourself.

Import Java.util.Scanner; Public classmain{ Public Static void Main(string[] args) {String strs1[] = {"RS","SP","PR"}; String strs2[] = {"SR","PS","RP"}; Scanner sc =NewScanner (System.inch);intT =sc.nextint (); while(t-->0){intn = sc.nextint ();intp1=0;intP2=0; String str1=NULL; String str2=NULL; String str=NULL; for(intI=0; i<n;i++) {str1 = Sc.next (); STR2 = Sc.next ();if(Str1.equals (STR2)) {Continue; } Boolean isstr1=false; STR=STR1+STR2; for(intj=0; j<strs1.length;j++) {if(Str.equals (Strs1[j]))                        {p1++; isstr1=true; Break; }                }if(ISSTR1)Continue; for(intj=0; j<strs2.length;j++) {if(Str.equals (Strs2[j])) {p2++; Break; }                }            }if(P1&GT;P2) {System. out. println ("Player 1"); }Else if(P1&LT;P2) {System. out. println ("Player 2"); }Else{System. out. println ("TIE"); }        }    }}

Hdoj (HDU) 2164 Rock, Paper, or Scissors?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.