Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- @SpringBootApplication
- public class YandexTestApplication {
- public static void main(String[] args) {
- SpringApplication.run(YandexTestApplication.class, args);
- int N;
- int K;
- int steps = 0;
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader("C:\\Users\\serge\\IdeaProjects\\YandexTest\\src\\main\\resources\\input.txt"));
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- String file = null;
- try {
- file = reader.readLine();
- N = Integer.parseInt(file);
- List<Integer> list = new ArrayList<>();
- List<Integer> listval = new ArrayList<>();
- List<Integer> ref = new ArrayList<>();
- file = reader.readLine();
- String[] nums = file.split(" ");
- for (String num : nums) {
- list.add(Integer.parseInt(num));
- }
- file = reader.readLine();
- nums = file.split(" ");
- for (int i = 0; i < N; i++) {
- listval.add(Integer.parseInt(nums[i]));
- }
- file = reader.readLine();
- K = Integer.parseInt(file);
- file = reader.readLine();
- nums = file.split(" ");
- for (int i = 0; i < K; i++) {
- ref.add(Integer.parseInt(nums[i]));
- }
- int temp, temp2;
- for (int i = 0; i < K - 1; i++) {
- temp = ref.get(i);
- temp2 = ref.get(i + 1);
- if (listval.get(list.indexOf(temp)) != listval.get(list.indexOf(temp2))) {
- steps++;
- }
- }
- try (FileWriter writer = new FileWriter("C:\\Users\\serge\\IdeaProjects\\YandexTest\\src\\main\\resources\\output.txt")) {
- writer.write(String.valueOf(steps));
- writer.flush();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement