View Code of Problem 7

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int i = 0; i < T; i ++) {
			int n = sc.nextInt();
			sc.nextLine();
			int[][] arr = new int[n][2];
			for(int j = 0; j < n; j ++) {
				String input = sc.nextLine();
				String[] split = input.split("=");
				arr[j][0] = Integer.parseInt(split[0]);
				arr[j][1] = Integer.parseInt(split[1]);
			}
			int m = sc.nextInt();
			for(int k = 0; k < m; k ++) {
				int t = sc.nextInt();
				int flag = 0;
				for(int l = 0; l < n; l ++) {
					if(t == arr[l][0]) {
						System.out.println(arr[l][1]);
						flag = 1;
					}
					if(t == arr[l][1]) {
						System.out.println(arr[l][0]);
						flag = 1;
					}
				}
				if(flag == 0) {
					System.out.println("UNKNOW");
				}
			}
			System.out.println();
			
		}
	}

}

Double click to view unformatted code.


Back to problem 7