PAT——1041. 考试座位号

每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。

输入格式:

输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。

考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,以空格分隔。

输出格式:

对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。

输入样例:

4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4

输出样例:

10120150912002 2
10120150912119 1


 1 package com.hone.basical;
 2 
 3 import java.util.ArrayList;
 4 import java.util.List;
 5 import java.util.Scanner;
 6 
 7 /**
 8  * 原题目:https://www.patest.cn/contests/pat-b-practise/1039
 9  * @author Xia
10  * 第一个思路:想着用二维数组的方式来存储数据,可是联想到对于准考证可能需要用long类型的数据
11  * 当时单独为了一个准考证开辟long类型的二维数组,空间极度浪费。
12  * (2)定义一个student的类,包含三个属性“准考证” “试机座位号” “考试座位号”
13  *    之前也有类似的处理,对多个具有相同属性的对象,可以定义成一个类
14  */
15 
16 public class basicalLevel1041searchSetNum {
17     public static void main(String[] args) {
18         Scanner in = new Scanner(System.in);
19         int n = in.nextInt();
20         List<stu_c> stulist = new ArrayList<>();
21         for (int i = 0; i < n; i++) {
22             stu_c s = new stu_c();
23             s.number = in.next();
24             s.tryNum = in.nextInt();
25             s.testNum = in.nextInt();
26             stulist.add(s);
27         }
28         int m = in.nextInt();
29         int[] mnum = new int[m];
30         for (int i = 0; i < m; i++) {
31             mnum[i] = in.nextInt();
32             for (int j = 0; j < stulist.size(); j++) {
33                 if (stulist.get(j).tryNum == mnum[i]) {
34                     System.out.println(stulist.get(j).number+" "+stulist.get(j).testNum);
35                 }
36             }
37         }
38         
39         
40     }
41 }
42 
43 //定义一个学生类
44 class stu_c {
45     String number;
46     int tryNum;
47     int testNum;
48     
49     public String getNumber() {
50         return number;
51     }
52     public void setNumber(String number) {
53         this.number = number;
54     }
55     public int getTryNum() {
56         return tryNum;
57     }
58     public void setTryNum(int tryNum) {
59         this.tryNum = tryNum;
60     }
61     public int getTestNum() {
62         return testNum;
63     }
64     public void setTestNum(int testNum) {
65         this.testNum = testNum;
66     }    
67     
68 }

 




posted @ 2017-12-06 10:54  SnailsCoffee  阅读(880)  评论(0编辑  收藏  举报