fork download
  1. import java.util.regex.*;
  2.  
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String t = "recede";
  9. System.out.println(encode(t));
  10. //System.out.println(Kata.encode(t));
  11. }
  12.  
  13. public static String encode(String word){
  14. StringBuilder result = new StringBuilder();
  15. char[] arr = word.toCharArray();
  16. for (char c : arr) {
  17. Pattern pattern = Pattern.compile("(?i)" + c + "[^" + c + "]*" + c);
  18. Matcher matcher = pattern.matcher(word);
  19. if (matcher.find())
  20. result.append(")");
  21. else
  22. result.append("(");
  23. }
  24. return result.toString();
  25. }
  26. }
Success #stdin #stdout 0.18s 58140KB
stdin
Standard input is empty
stdout
()()()