Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class VirusReplication {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- char[] s1 = bf.readLine().toCharArray();
- char[] s2 = bf.readLine().toCharArray();
- int startidx = -1;
- int endidx = -1;
- for (int i = 0; i < s2.length && i < s1.length; i++) {
- if (s1[i] != s2[i]) {
- startidx = i;
- break;
- }
- }
- if (startidx == -1 && s1.length != s2.length) {
- if (s1.length < s2.length)
- System.out.println(Math.max(s1.length, s2.length) - Math.min(s1.length, s2.length));
- else
- System.out.println(0);
- return;
- }
- for (int i = s1.length - 1, j = s2.length - 1; i >= 0 && j >= 0; i--, j--) {
- if (s1[i] != s2[j]) {
- endidx = j;
- break;
- }
- }
- if (endidx == -1 && s1.length != s2.length) {
- if (s1.length < s2.length)
- System.out.println(Math.max(s1.length, s2.length) - Math.min(s1.length, s2.length));
- else
- System.out.println(0);
- return;
- }
- if (endidx == -1 && startidx == -1) {
- System.out.println(0);
- return;
- }
- System.out.println(endidx - startidx + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement