Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] arrOne = Arrays
- .stream(scanner.nextLine().split(" "))
- .toArray(String[]::new);
- String[] arrTwo = Arrays
- .stream(scanner.nextLine().split(" "))
- .toArray(String[]::new);
- int frontEqualsElements = 0, backEqualsElements = 0,
- minArrLength = Math.min(arrOne.length, arrTwo.length);
- for (int i = 0; i < minArrLength; i++) {
- if (arrOne[i].equals(arrTwo[i])) {
- frontEqualsElements++;
- }
- }
- for (int i = 1; i <= minArrLength; i++) {
- if (arrOne[arrOne.length - i].equals(arrTwo[arrTwo.length - i])) {
- backEqualsElements++;
- }
- }
- System.out.println(Math.max(frontEqualsElements, backEqualsElements));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement