题解 | #查找学生信息# #写复杂了,淦#

查找学生信息

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

#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;

struct Student
{
    string name;
    string sex;
    int age;
    Student(string n,string s,int a)
        :name(n),sex(s),age(a){}

};
int main() 
{
    int n,m,age;
    string name,sex,index;
    unordered_map<string,Student> um;
    unordered_map<string,Student>::iterator it;
    while(cin>>n)
    {
        while(0<n--)
        {
            cin>>index>>name>>sex>>age;
            um.insert(pair<string,Student>(index,Student(name,sex,age)));
        }
        cin>>m;
        while(m--)
        {
            cin>>index;
            it=um.find(index);
            if(it!=um.end())
            {
                Student x=it->second;
                cout<<it->first<<" "<<x.name<<" "<<x.sex<<" "<<x.age<<endl;
            }
            else
            {
                cout<<"No Answer!"<<endl;
            }
        }
    }


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

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务