fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. class Solution {
  8.  
  9. static String super_reduced_string(String s){
  10. // Complete this function
  11. int i, j;
  12. while (!checkString(s))
  13. s = cutString(s);
  14. if (s.length() == 0)
  15. return "Empty String";
  16. else
  17. return s;
  18. }
  19.  
  20. static String cutString(String str)
  21. {
  22. for (int i = 0; i < str.length() - 1; i++)
  23. {
  24. if (str.substring(i, i+1).equals(str.substring(i+1, i+2)))
  25. str = str.substring(0, i) + str.substring(i+1); i--;
  26.  
  27. }
  28. return str;
  29. }
  30.  
  31. static boolean checkString(String str)
  32. {
  33. for (int j = 0; j < str.length()-1; j++)
  34. {
  35. if (str.charAt(j) == str.charAt(j+1))
  36. return false;
  37. }
  38. return true;
  39. }
  40.  
  41. public static void main(String[] args) {
  42. Scanner in = new Scanner(System.in);
  43. String s = in.next();
  44. String result = super_reduced_string(s);
  45. System.out.println(result);
  46. }
  47. }
  48.  
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
Standard input is empty
stdout

Standard output is empty

stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1371)
	at Solution.main(Main.java:43)