MHGOC01 - Editorial

Question

Rock, Paper, Scissors

Difficulty Level

Easy

Prerequisites

None

Code

include stdio.h

include string.h

int who_wins (char a, char b)

{

if ( a == ‘P’ && b == ‘R’ )

 return 1;

if ( a == ‘P’ && b == ‘S’ )

 return 2;

if ( a == ‘R’ && b == ‘P’ )

 return 2;

if ( a == ‘R’ && b == ‘S’ )

 return 1;

if ( a == ‘S’ && b == ‘R’ )

 return 2;

if ( a == ‘S’ && b == ‘P’ )

 return 1;

return 0;

}

int main ()

{

int data_pair;

scanf (“%d”, &data_pair);

getchar ();

int count_A = 0;

int count_B = 0;

while ( data_pair-- ) {

char a;

char b;

scanf ("%c %c", &a, &b);

if ( who_wins (a, b) == 1 ) {

 printf ("A WINS\n");

 count_A++;

}

else if ( who_wins (a, b) == 2 ) {

 printf ("B WINS\n");

 count_B++;

}

else

 printf ("DRAW\n");

}

if ( count_A > count_B )

 printf ("A WINS TOURNAMENT\n");

else

 printf ("B WINS TOURNAMENT\n");

return 0;

}