PTA L1-005 exam seat number (15 points)

Subject description:

PAT Each candidate will be assigned seat number two in the exam, the test machine is a seat, a seat is exam. Under normal circumstances, the first candidates in the admission test machine to obtain a seat number, the seating state into the test machine, the system displays the seat number of the candidate for an examination, the examination candidates need to change the test to take the seat. But some candidates late, test machine has ended, they can only receive the test machine took the seat numbers turn to you, find out their examination seat number from the background.

Input formats:

The first input line is given a positive integer N (≤1000), followed by N rows, each row gives the information for a candidate: 准考证号 试机座位号 考试座位号. Wherein 准考证号the 16-bit numbers, numbered from 1 to N seat. Enter the ticket number to ensure that everyone is different, and no time will two people assigned to the same seat.

After the candidate information, gives a positive integer M (≤N), followed by analysis of the M test machine to be queried row seat number, separated by a space.

Output formats:

Each seat number corresponding to the test machine to be queried, in a row corresponding to the output candidates ticket number and seat number examination, separated by a space.

Sample input:

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

Sample output:

3310120150912002 2
3310120150912119 1

Report problem solving:

1: bucket sort or through, how to build a barrel 1000, when the information is stored in accordance with the number of the test machine.

2: Benefits: Quick Find. Disadvantages: but a waste of space.

3: and https://blog.csdn.net/jun_____/article/details/103962906 this problem solution similar.

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1000+10;
struct people{
    char sno[20];//准考证号
    ll testNum, examNum;//测试号码,考试号码
}peoples[N];
int main(){
    ll n, m, t, e;
    char s[20];
    scanf("%lld", &n);
    for(ll i=0; i<n; ++i){
        scanf("%s%lld%lld", s, &t, &e);
        strcpy(peoples[t].sno, s);
        peoples[t].testNum = t, peoples[t].examNum = e;
    }
    scanf("%lld", &m);
    while(m--){
        ll x;
        scanf("%lld", &x);
        printf("%s %lld\n", peoples[x].sno, peoples[x].examNum);
    }
    return 0;
}

 

Published 76 original articles · won praise 0 · Views 3742

Guess you like

Origin blog.csdn.net/jun_____/article/details/103963287