fork download
  1. class M{
  2. static String c(String s){
  3. char[] a = s.toCharArray();
  4. int l = a.length,
  5. x,
  6. y;
  7. return l < 2
  8. ? s
  9. : "" + (l%2 > 0
  10. ? a[l/2]
  11. : (char)((x = a[l/2]) > (y = a[(l/2)-1])
  12. ? y + ((x-y)/2)
  13. : x + ((y-x)/2)));
  14. }
  15.  
  16. public static void main(String[] a){
  17. System.out.println(c("12345"));
  18. System.out.println(c("Hello"));
  19. System.out.println(c("Hiya"));
  20. System.out.println(c(""));
  21. System.out.println(c("x")); // Additional test case that will fail on some other answers
  22. }
  23. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
3
l
q

x