Rock, Paper, Scissors is a two player game, where each player simultaneously cho
ID: 3906814 • Letter: R
Question
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 in which 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 beats Paper (Scissors cut Paper) *Paper always beats Rock (Paper wraps Rock) The first value in the input file will be an integer t (0Explanation / Answer
The output program for your question is
Gets the no of test cases, then the number of rounds then the inputs for each round as R P S.
Finally prints the winner as Player 1 or Player 2, otherwise if there is no winner print TIE.
<code>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int tests,rounds;
char player1,player2;
srand(time(NULL));
scanf("%d",&tests);
// Loops through the number of test cases
for(int i=0;i<tests;i++){
int P1score =0,P2score =0;
scanf("%d",&rounds);
// Loops through the number of rounds
for(int j=0;j<rounds;j++){
scanf(" %c %c",&player1, &player2);
if(player1=='R'){
if(player2=='R'){
}
if(player2=='P'){
P2score= P2score + 1;
}
if(player2=='S'){
P1score = P1score + 1;
}
}
else if(player1=='P'){
if(player2=='P'){
}
if(player2=='S'){
P2score = P2score + 1;
}
if(player2=='R'){
P1score= P1score + 1;
}
}
else if(player1=='S'){
if(player2=='S'){
}
if(player2=='P'){
P1score= P1score + 1;
}
if(player2=='R'){
P2score = P2score + 1;
}
}
else{
printf("Wrong inputs ");
}
}
if(P2score > P1score ){
printf("Player 2 ");
}
else if(P2score < P1score ){
printf("Player 1 ");
}
else if(P2score = P1score ){
printf("TIE ");
}
}
return 0;
}
</code>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.