Winner in the Rock | Java 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
import java . util . * ; class GFG { static String winner ( String moves ) { HashMap < Character , Integer > data = new HashMap < Character , Integer > ( ) ; data . put ( ' R ' , 0 ) ; data . put ( ' P ' , 1 ) ; data . put ( ' S ' , 2 ) ; if ( moves . charAt ( 0 ) == moves . charAt ( 1 ) ) { return " Draw " ; } if ( ( ( data . get ( moves . charAt ( 0 ) ) | 1 << ( 2 ) ) - ( data . get ( moves . charAt ( 1 ) ) | 0 << ( 2 ) ) ) % 3 != 0 ) { return " A " ; } return " B " ; } static void performQueries ( String arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( winner ( arr [ i ] ) + "NEW_LINE"); } public static void main ( String [ ] args ) { String arr [ ] = { " RS " , " SR " , " SP " , " PP " } ; int n = arr . length ; performQueries ( arr , n ) ; } }