PTA 乙级 1041 考试座位号 (15分) C++

 创建学生考试信息结构体,根据输入的n,建立结构体数组

C++

 1 #include<iostream>
 2 #include<vector>
 3 
 4 using namespace std;
 5 
 6 //学生信息结构体
 7 typedef struct {            
 8     string exam;
 9     int sn;
10     int seat;
11 }Student;
12 
13 int main() {
14     int n = 0, m = 0, num = 0;
15     cin >> n;
16     vector<Student> all(n);            //创建n个学生信息结构体数组,储存学生信息方便后续输出
17     for (int i = 0; i < n; ++i) {
18         cin >> all[i].exam >> all[i].sn >> all[i].seat;        //输入学生信息
19     }
20     cin >> m;
21     for (int i = 0; i < m; ++i) {
22         cin >> num;                
23         for (int j = 0; j < n; j++) {        
24             if (all[j].sn == num)                    //找到对应试机座位号输出
25                 cout << all[j].exam << " " << all[j].seat << endl;
26         }
27     }
28     return 0;
29 }

水的一题,就是题干有点麻烦

原文地址:https://www.cnblogs.com/SCP-514/p/13388085.html