1041 Exam seat number (15 points) Python

Title link: https://pintia.cn/problem-sets/994805260223102976/problems/994805281567916032

Each PAT candidate will be assigned two seat numbers when taking the test, one is the test seat and the other is the test seat. Under normal circumstances, candidates first get the test seat number when entering the venue. After entering the test machine state, the system will display the test taker’s test seat number, and the test taker needs to change to the test seat during the test. However, some candidates are late and the test machine is over. They can only ask you for help with the test machine seat number they received, and find out their test seat number from the backstage.

Input format:
Input the first line to give a positive integer N (≤1000), and then N lines, each line gives one candidate's information: admission ticket number, test machine seat number, test seat number. The admission ticket number is composed of 16 digits, and the seats are numbered from 1 to N. Enter to ensure that everyone's admission ticket number is different, and no two people will be assigned to the same seat at any time.

After the candidate information, give a positive integer M (≤N), and then give M test machine seat numbers to be queried in a row, separated by spaces.

Output format:
corresponding to each test machine seat number that needs to be queried, output the test admission ticket number and test seat number of the corresponding candidate in one line, separated by a space.

Input sample:

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

Sample output:

3310120150912002 2
3310120150912119 1

Problem-solving ideas:

This question is mainly for investigating and querying, so dictit can't be more suitable for this question.

First, create an empty dictionary. According to the user's input, the test machine seat number is used as dictthe test machine seat number key, and the test admission ticket number and the test seat number are valuestored dictin. Note here that the admission ticket number and seat number are strstored as a whole , remember to put a space in between. In this way, the preparations are done.

Then save the obtained user input as one list, and traverse the list to output each item as the corresponding value in the keysearch dict.

AC code:

n = int(input())
dic = {
    
    }
for i in range(n):
    s = input().split()
    dic[s[1]] = s[0] + ' ' + s[2]
n = input()
select = input().split()
for i in select:
    print(dic[i])

Guess you like

Origin blog.csdn.net/weixin_44289959/article/details/110959068