Winner in the Rock | C ++ implementation of the approach ; Function to return the winner of the game ; Both the players chose to play the same move ; Player A wins the game ; Function to perform the queries ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string winner ( string moves ) { map < char , int > data ; data [ ' R ' ] = 0 ; data [ ' P ' ] = 1 ; data [ ' S ' ] = 2 ; if ( moves [ 0 ] == moves [ 1 ] ) { return " Draw " ; } if ( ( ( data [ moves [ 0 ] ] | 1 << ( 2 ) ) - ( data [ moves [ 1 ] ] | 0 << ( 2 ) ) ) % 3 ) { return " A " ; } return " B " ; } void performQueries ( string arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << winner ( arr [ i ] ) << endl ; } int main ( ) { string arr [ ] = { " RS " , " SR " , " SP " , " PP " } ; int n = sizeof ( arr ) / sizeof ( string ) ; performQueries ( arr , n ) ; return 0 ; }