Hi all,

Can someone please help me identify the failing test case, the testset runs 
fine but in submitting I get a runtime error.

I have followed the below logic

I'm checking for the each move, 
- if at any moment all bots make the same move, i return the winning move 
appended to the buffered moves.
- if at any moment all bots make different moves, I return IMPOSSIBLE
- if there are just two kinds of move, then i pick a winning move n remove the 
other opponents.

import java.io.*;
import java.util.*;

public class Solution {
        public static void main(String[] args) throws FileNotFoundException, 
UnsupportedEncodingException {
                Scanner in = new Scanner(new BufferedReader(new 
InputStreamReader(System.in)));
                int T = in.nextInt();
                for (int testcase = 1; testcase <= T; ++testcase) {
                        A = in.nextInt();
                        Ci = new String[A];
                        for (int i = 0; i < A; i++) {
                                Ci[i] = new String(in.next());
                        }
                        String winP = winningProgram3();
                        System.out.println("Case #" + testcase + ": " + winP);
                }
                in.close();
        }

        static int A;
        static String[] Ci;

        public static String winningProgram3() {
                StringBuffer winP = new StringBuffer();
                int progLen = Ci[0].length();
                Set<Integer> oppoLeft = initilizeOppo();
                for (int i = 0; i < progLen; i++) {
                        Set<Character> types = new HashSet<>();
                        Iterator<Integer> it = oppoLeft.iterator();
                        while (it.hasNext()) {
                                types.add(Ci[it.next()].charAt(i));
                        }
                        switch (types.size()) {
                        case 1:
                                return 
winP.append(winningMove(Ci[0].charAt(i))).toString();
                        case 2:
                                int oppoLeftInd = 0;
                                char curMove = getNextMove(types);
                                winP.append(curMove);
                                for (int j = 0; j < Ci.length; j++) {
                                        if (oppoLeft.contains(j)) {
                                                if (curMove != Ci[j].charAt(i)) 
{
                                                        oppoLeft.remove(new 
Integer(j));
                                                } else {
                                                        oppoLeftInd = j;
                                                }
                                        }
                                }
                                if (i == progLen - 1) {
                                        
winP.append(winningMove(Ci[oppoLeftInd].charAt(0)));
                                }
                                break;
                        case 3:
                                return "IMPOSSIBLE";
                        }
                }
                return winP.toString();
        }

        private static char getNextMove(Set<Character> types) {
                if (types.contains('R') && types.contains('P'))
                        return 'P';
                if (types.contains('S') && types.contains('R'))
                        return 'R';
                return 'S';
        }

        private static Set<Integer> initilizeOppo() {
                Set<Integer> tempOppo = new HashSet();
                for (int i = 0; i < A; i++) {
                        tempOppo.add(i);
                }
                return tempOppo;
        }

        public static char winningMove(char M) {
                if (M == 'R')
                        return 'P';
                if (M == 'S')
                        return 'R';
                return 'S';
        }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/f9b40e20-f01e-4a3a-89ce-c3465df0913a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to