View Code of Problem 7

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int t= Integer.parseInt(scanner.nextLine());
        while (t-->0){
            String temp=scanner.nextLine();
            int n= Integer.parseInt(scanner.nextLine());
            List<Integer> map=new ArrayList<>();
            int l=0;
            for(int i=0;i<n;i++){
                String[] s=scanner.nextLine().split("=");
                map.add(Integer.parseInt(s[0]));
                map.add(Integer.parseInt(s[1]));
            }
            int m= Integer.parseInt(scanner.nextLine());
            for(int i=0;i<m;i++){
                int num= Integer.parseInt(scanner.nextLine());
                if(map.contains(num)){
                    if(map.indexOf(num)%2==0){
                        System.out.println(map.get(map.indexOf(num)+1));
                    }
                    else {
                        System.out.println(map.get(map.indexOf(num)-1));
                    }
                }
                else{
                    System.out.println("UNKNOW");
                }
            }
            temp=scanner.nextLine();
        }
    }
}

Double click to view unformatted code.


Back to problem 7