fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class Main {
  6.  
  7. public static void main(String[] args) {
  8. String input;
  9. while ((input = br.readLine()) != null) {
  10. System.out.printf("%s\n", condense4(input));
  11. }
  12. } catch (IOException e) {
  13. e.printStackTrace();
  14. }
  15. }
  16.  
  17. private static String condense4(String input) {
  18. String[] words = input.split("\\s");
  19. for (int i = 0; i < words.length - 1; i++) {
  20. String cur = words[i];
  21. String next = words[i + 1];
  22. for (int j = next.length() - 1; j > 0; j--) {
  23. if (cur.endsWith(next.substring(0, j)))
  24. return condense4(input.replaceFirst(cur + " " + next,
  25. new StringBuilder().append(cur).append(next.substring(j, next.length())).toString()));
  26. }
  27. }
  28. return input;
  29. }
  30. }
Success #stdin #stdout 0.04s 4386816KB
stdin
I heard the pastor sing live verses easily.
Deep episodes of Deep Space Nine came on the television only after the news.
Digital alarm clocks scare area children.
stdout
I heard the pastor sing liverses easily.
Deepisodes of Deep Space Nine came on the televisionly after the news.
Digitalarm clockscarea children.