当前位置:网站首页>Seat number of Pat grade B 1041 test (15 points)

Seat number of Pat grade B 1041 test (15 points)

2022-06-21 07:22:00 myriadddddd

Every PAT Candidates are assigned two seat numbers when they take the exam , One is a test seat , One is the exam seat . Under normal circumstances , Candidates will get the seat number of the test machine before entering , After entering the test state , The system will display the test seat number of the candidate , Candidates need to change their seats during the examination . But some candidates are late , The test run is over , They can only ask you for help with the number of the test seat they have received , Find out their test seat number from the background .

Input format :

The first line of input gives a positive integer N(≤1000), And then N That's ok , Each line gives a candidate's information : Ticket number Test seat number Test seat number . among Ticket number from 16 Digit composition , Seat from 1 To N Number . Input to make sure that everyone's admission number is different , And at no time will two people be assigned to the same seat .

After candidate information , Give a positive integer M(≤N), In the next line M Test seat numbers to be inquired , Space off .

Output format :

Corresponding to each seat number to be inquired , Output the candidate's pass number and seat number in one line , Intermediate use 1 Space separation .

sample input :

4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4

sample output :

3310120150912002 2
3310120150912119 1

analysis :

This question is relatively simple , As long as the three attributes are stored, check whether the machine test number at the corresponding position is the same when querying .

Code :

#include <iostream>
#include <vector>

using namespace std;

struct  Node {
    string id;      //  Candidate number 
    int computerId; //  Machine test No 
    int rank;       //  ranking 
};

int main() {
    int N, M;
    cin >> N;
    vector<Node> ans(N);

    for (int i = 0; i < N; i++)
        cin >> ans[i].id >> ans[i].computerId >> ans[i].rank;

    cin >> M;
    for (int i = 0; i < M; i++) {
        int cid;
        cin >> cid;
        for (int i = 0; i < N; i++) {   //  The examinee number and ranking corresponding to the machine test number of the circular query 
            if (ans[i].computerId == cid) {
                cout << ans[i].id << " " << ans[i].rank << endl;
                break;
            }
        }
    }

    return 0;
}
原网站

版权声明
本文为[myriadddddd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221515505104.html