PAT乙级1041
题目链接
https://pintia.cn/problem-sets/994805260223102976/problems/994805281567916032
题解
简单的信息录入和查询而已。
根据需求,使用试机座位号作为学生的标识进行信息录入和查询。
// PAT BasicLevel 1041
// https://pintia.cn/problem-sets/994805260223102976/problems/994805281567916032
#include <iostream>
#include <string>
using namespace std;
// 学生类
class Student{
public:
    string zhunkaozhenghao;
    int kaoshizuoweihao;
    Student() {}
    Student(string zhunkaozhenghao, int kaoshizuoweihao){
        this->zhunkaozhenghao = zhunkaozhenghao;
        this->kaoshizuoweihao = kaoshizuoweihao;
    }
    void print(){cout << zhunkaozhenghao << ' ' << kaoshizuoweihao << endl;}
};
int main()
{
    // n个学生
    int n;
    Student stuArr[1001];   // 学生信息
    string zhunkaozhenghao; // 准考证号
    int kaoshizuoweihao;    // 考试座位号
    int shijizuoweihao;     // 试机位号
    // 录入学生信息
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> zhunkaozhenghao >> shijizuoweihao >> kaoshizuoweihao;
        stuArr[shijizuoweihao]=Student(zhunkaozhenghao,kaoshizuoweihao);
    }
    // 查询m个学生的信息并输出
    int m;
    cin >> m;
    for(int i=0;i<m;++i){
        cin >>shijizuoweihao;
        stuArr[shijizuoweihao].print();
    }
    //system("pause");
    return 0;
}
作者:@臭咸鱼
转载请注明出处:https://www.cnblogs.com/chouxianyu/
欢迎讨论和交流!
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号