题解 | #查找学生信息#

查找学生信息

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

#include <iostream>
#include <algorithm>
#include "cstring"
#include "map"
#include "unordered_map"
using namespace std;
typedef struct stu {
    string name;
    string sex;
    int age;
} stu;
unordered_map<string, stu> M; //  用散列表
int n,m;
int main() {
    cin >> n;
    while (n--) {
        string id,name,sex;
        int age;
        cin >>id >> name >>sex >>age;
        stu student;
        student.name=name;
        student.sex=sex;
        student.age=age;
        M[id] = student;
    }
    cin >>m;
    while(m--){
        string search;
        cin >> search;
        if(M.count(search) == 0){
            cout << "No Answer!" << endl;
        }else {
            stu lll= M[search];
            cout <<search<<' '<<lll.name<<' '<<lll.sex<< ' '<<lll.age<<endl;
        }


    }


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

用 哈希表 存

全部评论

相关推荐

07-09 19:25
门头沟学院 Java
这是要把每一个投校招的都开盒吗?
26届之耻将大局逆转:裁人的时候一次性追回餐费
点赞 评论 收藏
分享
屌丝逆袭咸鱼计划:心态摆好,man,晚点找早点找到最后都是为了提升自己好进正职,努力提升自己才是最关键的😤难道说现在找不到找的太晚了就炸了可以鸡鸡了吗😤早实习晚实习不都是为了以后多积累,大四学长有的秋招进的也不妨碍有的春招进,人生就这样
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 12:11
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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