Advertisement
Guest User

Untitled

a guest
May 30th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5.  
  6. public class VirusReplication {
  7.  
  8. /**
  9. * @param args
  10. * @throws IOException
  11. */
  12. public static void main(String[] args) throws IOException {
  13. BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  14. char[] s1 = bf.readLine().toCharArray();
  15. char[] s2 = bf.readLine().toCharArray();
  16.  
  17.  
  18.  
  19. int startidx = -1;
  20. int endidx = -1;
  21.  
  22. for (int i = 0; i < s2.length && i < s1.length; i++) {
  23. if (s1[i] != s2[i]) {
  24. startidx = i;
  25. break;
  26. }
  27. }
  28.  
  29. if (startidx == -1 && s1.length != s2.length) {
  30. if (s1.length < s2.length)
  31. System.out.println(Math.max(s1.length, s2.length) - Math.min(s1.length, s2.length));
  32. else
  33. System.out.println(0);
  34. return;
  35. }
  36.  
  37.  
  38. for (int i = s1.length - 1, j = s2.length - 1; i >= 0 && j >= 0; i--, j--) {
  39. if (s1[i] != s2[j]) {
  40. endidx = j;
  41. break;
  42. }
  43. }
  44.  
  45. if (endidx == -1 && s1.length != s2.length) {
  46. if (s1.length < s2.length)
  47. System.out.println(Math.max(s1.length, s2.length) - Math.min(s1.length, s2.length));
  48. else
  49. System.out.println(0);
  50. return;
  51. }
  52.  
  53. if (endidx == -1 && startidx == -1) {
  54. System.out.println(0);
  55. return;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. System.out.println(endidx - startidx + 1);
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement