fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. class Main {
  4.  
  5. public static void main(String[] a){
  6. // Your version
  7. String[] o = c("abc^d+ef^g + hijk^l - M^NO^P (Ag^+)");
  8. System.out.println(o[0]);
  9. System.out.println(o[1]);
  10.  
  11. // My version
  12. o = d("abc^d+ef^g + hijk^l - M^NO^P (Ag^+)".toCharArray());
  13. System.out.println(o[0]);
  14. System.out.println(o[1]);
  15. }
  16.  
  17. static String[] c(String i){
  18. String[] r = {"",""};
  19. for(int j = 0; j < i.length(); j++){
  20. char c = i.charAt(j);
  21. r[0] += c == 94 ? i.charAt(++j) : 32;
  22. r[1] += c == 94 ? 32 : c;
  23. }
  24. return r;
  25. }
  26.  
  27. static String[] d(char[] i){
  28. String[] r = {"",""};
  29. for(char j = 0, c; j < i.length; j++){
  30. c = i[j];
  31. r[0] += c == 94 ? i[++j] : 32;
  32. r[1] += c == 94 ? 32 : c;
  33. }
  34. return r;
  35. }
  36. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
   d   g       l    N P    + 
abc +ef  + hijk  - M O  (Ag )
   d   g       l    N P    + 
abc +ef  + hijk  - M O  (Ag )