import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
/**
* @author jadexu
* @// TODO: 2020/12/28
* 每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。
* 正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,
* 考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,
* 他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
* 输入格式:
* 输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:准考证号 试机座位号 考试座位号。
* 其中准考证号由 16 位数字组成,座位从 1 到 N 编号。
* 输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
* 考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。
* 输出格式:
* 对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
*/
public static void main(String[] args) throws IOException {
//方法1
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int amount = Integer.parseInt(br.readLine());
HashMap<String,String[]> examinees = new HashMap<>();
while (amount-->0){
String[] line = br.readLine().split(" ");
examinees.put(line[1],new String[]{line[0],line[2]});
}
int num = Integer.parseInt(br.readLine());
String[] nums = br.readLine().split(" ");
for (int i = 0; i < num; i++) {
String[] result = examinees.get(nums[i]);
System.out.println(result[0]+" "+result[1]);
}
//方法2:部分测试用例运行超时
// Scanner in = new Scanner(System.in);
// int amount = in.nextInt();
// long[][] examinees = new long[amount][];
// for (int i = 0; i < examinees.length; i++) {
// examinees[i] = new long[]{in.nextLong(), in.nextInt(), in.nextInt()};
// }
// int num = in.nextInt();
// int[] nums = new int[num];
// for (int i = 0; i < nums.length; i++) {
// nums[i] = in.nextInt();
// for (int j = 0; j < examinees.length; j++) {
// if(nums[i] == examinees[j][1]){
// System.out.println(examinees[j][0]+" "+examinees[j][2]);
// break;
// }
// }
// }
}
}
PTA习题集-团体程序设计天梯赛L1-005
最新推荐文章于 2022-01-04 11:09:54 发布