L1-005 考试座位号 - java

题目解析

给定一些考生信息

输出 试机座位对应考生 的 准考证号 和 考试座位号码

解题思路

因为题目保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上
所以我们直接可以map去存储试机座位号上的人是谁即可
然后输出 该试机座位号上 准考证号与考试座位号

代码

import java.io.*;
import java.math.*;
import java.util.*;

public class Main
{

	public static void main(String[] args) throws IOException
	{
		int n = Integer.valueOf(sc.readLine());
		TreeMap<Integer, String> list = new TreeMap<Integer, String>();
		while (n-- > 0)
		{
			String s[] = sc.readLine().split(" ");
			String a = s[0]; // 准考证号
			int b = Integer.valueOf(s[1]); // 试机座位号
			int c = Integer.valueOf(s[2]);// 考试座位号
			list.put(b, a + " " + c);
		}

		int m = Integer.valueOf(sc.readLine());
		String s[] = sc.readLine().split(" ");
		for (int i = 0; i < m; i++)
		{
			int x = Integer.valueOf(s[i]);
			out.println(list.get(x));
		}

		out.flush();
		out.close();
	}

	static BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter out = new PrintWriter(System.out);
}


团体程序设计天梯赛-练习集-java

赞赏