fork download
  1. import java.io.PrintWriter;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public void run(){
  6. byte[] a, b;
  7. Scanner in = new Scanner(System.in);
  8. PrintWriter out = new PrintWriter(System.out);
  9.  
  10. a = (in.nextLine() + 'A').getBytes();
  11. b = (in.nextLine() + 'A').getBytes();
  12.  
  13. int fullLength = a.length + b.length - 2, ai = 0, bi = 0;
  14.  
  15. for(int i = 0; i < fullLength; i++){
  16. if(a[ai] > b[bi]) {
  17. out.print((char) b[bi]);
  18. bi++;
  19. }
  20. else if(a[ai] < b[bi]) {
  21. out.print((char) a[ai]);
  22. ai++;
  23. }
  24. else {
  25. if(a[ai + 1] > b[bi + 1]) {
  26. out.print((char) b[bi]);
  27. bi++;
  28. }
  29. else if(a[ai + 1] < b[bi + 1]) {
  30. out.print((char) a[ai]);
  31. ai++;
  32. }
  33. else {
  34. if(a[a.length - 2] >= b[b.length - 2]) {
  35. out.print((char) b[bi]);
  36. bi++;
  37. }
  38. else {
  39. out.print((char) a[ai]);
  40. ai++;
  41. }
  42. }
  43. }
  44. }
  45.  
  46. out.flush();
  47. out.close();
  48. }
  49.  
  50. public static void main(String[] args) {
  51. new Main().run();
  52. }
  53. }
Success #stdin #stdout 0.19s 61040KB
stdin
125
34
stdout
12345