题解 | #查找学生信息#

查找学生信息

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

#include <iostream>
#include "unordered_map"
using namespace std;
struct student {
    string name;
    string sex;
    int age;
    
    
};
int main() {
    int N;
    while (cin >> N) { // 注意 while 处理多个 case
        // cout << a + b << endl;
        unordered_map <int, student> myMap;
        while (N--) {
            int num;
            string name;
            string sex;
            int age;
            cin >> num >> name >> sex >> age;
            // myMap.insert(pair<int,student>(num,student(name, sex, age))) ;
            student temp;
            temp.name=name;
            temp.age=age;
            temp.sex=sex;
            myMap[num]=temp;//使用下标访问时结构体必须是可默认构造的
        }
        int M;
        cin >> M;
        while (M--) {
            int num;
            cin >> num;
            if (myMap.find(num) == myMap.end())
                cout << "No Answer!" << endl;
            else {
                student result = myMap.find(num)->second;
                cout << num << ' ' << result.name << ' ' << result.sex << ' ' << result.age <<
                     endl;
            }

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

全部评论

相关推荐

昨天 10:56
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:31
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
07-07 11:33
江南大学 Java
已经在暑假实习了&nbsp;,没有明确说有hc,纠结实习到八月份会不会有点影响秋招毕竟感觉今年好多提前批
程序员小白条:92的话准备提前批,其他没必要,没面试机会的,而且你要准备充分,尤其八股和算法题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务