A very exciting Paper-Rock-Scissors tournament has just begun! In qualifications, each player must face all his opponents in head to head games consisting of 5 throws. On each throw, each player will choose one of the following: Paper (‘P’), Rock (‘R’) or Scissors (‘S’). The winner of a throw is determined as follows:

Paper always wins against Rock

Rock always wins against Scissors

Scissors always win against Paper

In case both players make the same choice, it’s a tie and no one wins.

The winner of a game is the player who wins more throws. If both players win the same number of throws, the game ends in a tie (since these are qualifications, ties are allowed). To determine who passed the qualifications, a scoring system is implemented as follows:

For every game won, the player is awarded one point.

For every game tied, the player is awarded half of a point.

For every game lost, the player is awarded zero points.

Only a single player will pass the qualifications, namely the player with the most points. If several players have the same amount of points, the player which comes first in the input wins.

All players observe a simple strategy: each of them prepares a sequence of throws and plays the same sequence in every game. Write a program that will receive a String[] players representing the sequence of throws for all players and returns the 0-based index of the player who will pass the qualifications. Each element of players will contain exactly 5 characters. Character ‘P’ represents a Paper throw, ‘S’ represents a Scissors throw, and ‘R’ represents a Rock throw.

import java.util.Arrays;

public class PaperRockScisQuals {

public int whoPassed(String[] players) {
double[] point = new double[players.length];
for (int i = 0; i < point.length; i++) {

for (int i = 0; i < players.length; i++) {
for (int j = i+1; j < players.length; j++) {
int ipoint=0;
int jpoint=0;
for (int k = 0; k < 5; k++) {
if (ipoint==jpoint) {
}else if(ipoint>jpoint){

double max=0;
int max_index=0;
for (int i = 0; i < point.length; i++) {
if (point[i]>max) {
return max_index;

public int RSP(char s1,char s2){
if (s1==’R’) {
if (s2==’S’) {
return 1;
}else if (s1==’S’) {
return 1;
}else {
if (s2==’R’) {
return 1;
return 0;