El sábado, 13 de abril de 2019, 23:53:06 (UTC+2), [email protected]  escribió:
> How do test Java interactive solution in general?
> 
> I tried following two steps locally but it hangs. Submit the solution I got 
> TLE.
> 
> > javac GolfGophers.java
> > python interactive_runner.py python GolfGophers_testing_tool.py 0 -- java 
> > GolfGophers
> 
> The Java code:
>   static void judge(Scanner in, int[] input, int[] output) {
>     StringBuilder sb = new StringBuilder();
>     for (int i = 0; i < 18; i++) {
>       sb.append(input[i] + " ");
>     }
>     System.out.println(sb.toString());
>     System.out.flush();
>     for (int i = 0; i < 18; i++) {
>       output[i] = in.nextInt();
>       System.err.println(output[i]);
>     }
>   }
> 
>   static int judge(Scanner in, int count) {
>     System.out.println(count);
>     System.out.flush();
>     return in.nextInt();
>   }
> 
>   public static void main(String[] args) {
>     Scanner in = new Scanner(System.in);
>     int T = in.nextInt();
>     for (int t = 1; t <= T; t++) {
>       int N = in.nextInt();
>       int M = in.nextInt();
>       Map<Integer, Integer> sumcounts = new HashMap<>();
>       int[] input = new int[18];
>       int[] output = new int[18];
>       for (int k = 0; k < Math.min(N, 100); k++) {
>         for (int i = 0; i < 18; i++) {
>           input[i] = 18;
>         }
>         judge(in, input, output);
>         int sum = 0;
>         for (int i = 0; i < 18; i++) {
>           sum += output[i];
>         }
>         sumcounts.put(sum, sumcounts.getOrDefault(sum, 0)+1);
>       }
>       // sort sumcounts by value
>       TreeMap<Integer, Integer> sortedMap = new TreeMap<>(new 
> ValueComparator(sumcounts));
>       sortedMap.putAll(sumcounts);
>       int response = judge(in, sortedMap.firstKey());
>     }
>     in.close();
>   }

I've realized that it's possible to debug the java code by specifying the right 
parameters in the command to launch java.

Of course the details vary for each environment but here's how it's worked for 
me:

1) Launch the interactive tool with this command:
python interactive_runner.py python testing_tool.py 0 -- java -Xdebug 
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y,quiet=y Solution 

2) In Eclipse, create a debug configuration of type "Remote java application" 
and indicate the parameters server=localhost and port=8000

-- 
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/6261f32e-ac35-485a-ae95-7ad7da1a9655%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to