fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main
  6. {
  7. public static boolean check(StringBuilder a, StringBuilder b) {
  8. if(a.length()==b.length()) {
  9. for(int i = 0; i < a.length(); i++) {
  10. if(a.charAt(i) != b.charAt(i)) return false;
  11. }
  12. }
  13. return true;
  14. }
  15.  
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. int n, m, z;
  19. StringBuilder a = new StringBuilder();
  20. StringBuilder b = new StringBuilder();
  21. StringBuilder c = new StringBuilder();
  22. Scanner in = new Scanner(System.in);
  23. a.append( in.nextLine());
  24. b.append( in.nextLine());
  25. StringBuilder d = new StringBuilder(b);
  26. n = b.length();
  27. m = a.length();
  28. c = new StringBuilder(a.substring(m - n, m));
  29. if(a.toString().contains(b.toString()) != true) {
  30. for (int i = 1; i<=n && check(b,c) != true; i++) {
  31. b.delete(n - i,m);
  32. c.delete(0, 1);
  33. }
  34. z = c.length();
  35. d.delete(0,z);
  36. System.out.print(a);
  37. System.out.print(d);
  38. }
  39. else System.out.print(a);
  40. System.exit(0);
  41. }
  42. }
Success #stdin #stdout 0.1s 35376KB
stdin
compressing
single
stdout
compressingle