Java for IOI 2015

Revision en5, by microtony, 2015-06-21 06:15:24

UPD: arti commented that they will be using Oracle JDK. Thanks!

I maintain a online judge which uses the CMS isolate sandbox. I was trying to support Java so I looked at CMS itself, and found that they are using gcj (GNU Compiler for Java) as you can see in this commit.

https://github.com/cms-dev/cms/commit/cf949952424677e0b0762eec5e461e33f85eecb3

Of course this doesn't mean they will definitely use gcj and we should wait for their announcement. Disclaimer: I am not a IOI participant nor use Java in competitive programming. But I don't think they will support OpenJDK/Oracle as I (almost always) get memory allocation error when running JVM within isolate sandbox.

gcj is the default java installation in Ubuntu. So far I faced two bugs. (These bugs are related to I/O and since IOI uses interface file so it may not be a problem.)

1) Formatted floating point numbers will become empty

public class Task {
  public static void main(String[] args) {
    System.out.format("$%.3f\n", 0.9876);
  }
}
Expected output: $0.988
Program output: $

2) Scanner class does not work with Scanner.in.read(). Even if you are trying to scan integers only, you have to press enter several times. This does not happen when you use file redirection.

import java.util.*;
import java.io.*;
public class Task {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(System.in);
    System.out.print((char) System.in.read());
    System.out.println(in.nextInt());
  }
}
Input: A5
Expected Output: A5
Program: 
(strange character)Exception in thread "main" java.util.InputMismatchException: "A5" is not an integer
   at java.util.Scanner.myNextInt(libgcj.so.15)
   at java.util.Scanner.nextInt(libgcj.so.15)
   at java.util.Scanner.nextInt(libgcj.so.15)
   at Task.main(Task.java)
Tags ioi, java

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English microtony 2015-06-21 06:15:24 89 Tiny change: '**Update: ** [user:a' -
en4 English microtony 2015-06-18 17:12:08 689 Tiny change: 'work with Scanner.in.read(). Even if ' - (published)
en3 English microtony 2015-06-18 06:13:42 2 Tiny change: 's blame:\n![blame]' -> 's blame:\n\n![blame]'
en2 English microtony 2015-06-18 06:13:23 113
en1 English microtony 2015-06-18 06:08:38 1354 Initial revision (saved to drafts)