题解 | #查找学生信息#

查找学生信息

https://www.nowcoder.com/practice/fe8bff0750c8448081759f3ee0d86bb4

#include <iostream>
#include <map>
using namespace std;

struct Student{
    string name;
    string gender;
    int age;
    Student(string name1, string gender1, int age1):name(name1), gender(gender1), age(age1){}
};

int main() {
    int n;
    cin >> n;
    map<string, Student> students;

    while(n --){
        string no, name, gender;
        int age;
        cin >> no >> name >> gender >> age;
        Student stu(name, gender, age);
        students.insert(pair<string, Student>(no, stu));
    }
    cin >> n;
    while(n --){
        string no;
        cin >> no;
        auto t = students.find(no);
        if(t == students.end()){
            cout << "No Answer!" << endl;
        }else{
            cout << no << " " << t->second.name << " " << t->second.gender << " " << t->second.age << endl;
        }
    }

    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务