fork download
  1. import java.util.Scanner;
  2. class Main {
  3. public static void main(String[] args) {
  4. Scanner k = new Scanner (System.in);
  5. while (k.hasNext()){
  6. String sentence = k.nextLine();
  7. Scanner parser = new Scanner(sentence);
  8. int size = 0;
  9. while (parser.hasNext()){
  10. size++;
  11. parser.next();
  12. }
  13. String [] words = new String [size];
  14. String [] cocatnated = new String [size];
  15. boolean [] overlapped = new boolean[size];
  16. parser = new Scanner(sentence);
  17. for (int i = 0; i < words.length; i++) {
  18. words[i]=parser.next();
  19. overlapped[i] = false;
  20. }
  21. for (int i=0;i<words.length-1;i++){
  22. int j;
  23. boolean isOverlap = false;
  24. int size1 = words[i].length();
  25. int size2 = words[i+1].length();
  26. for (j=0; j<size1 && j<size2;j++){
  27. if (words[i+1].charAt(0) == words[i].charAt(size1-1-j)){
  28. String sub1 = words[i].substring(size1-1-j, size1);
  29. String sub2 = words[i+1].substring(0, j+1);
  30. if (sub1.compareTo(sub2) == 0){
  31. String temp = words[i].substring(0, size1).concat(words[i+1].substring(j+1, size2));
  32. cocatnated[i] = temp;
  33. isOverlap = true;
  34. overlapped[i+1] = true;
  35. }
  36. }
  37. if (!isOverlap){
  38. cocatnated[i] = words[i];
  39. cocatnated[i+1] = words[i+1];
  40. }
  41. }
  42. }
  43. for (int i = 0; i < cocatnated.length; i++) {
  44. if (overlapped[i] == false){
  45. System.out.print(cocatnated[i]+" ");
  46. }
  47. }
  48. System.out.println();
  49. }
  50.  
  51. }
  52. }
Success #stdin #stdout 0.06s 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 clockscare children.