题解 | 查找学生信息

查找学生信息

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

#include <iostream>
#include <random>
#include <vector>
using namespace std;
struct student
{
    string num;
    string name;
    string sex;
    int age;
};
int main() {
    int N;
    vector<student>std;
    while(cin>>N)
    {
        std.clear();
        std.resize(N);
        for(int i=0;i<N;i++)
        {
            //遍历数组一共N行信息
            cin>>std[i].num>>std[i].name>>std[i].sex>>std[i].age;
        }
        int M;
        string temp_num;
        cin>>M;
        for(int i=0;i<M;i++)
        {
            //输入要查询的num
            cin>>temp_num;
            bool found =false;
            for(int j=0;j<std.size();j++)
            {
                if(temp_num==std[j].num)
                {cout<<std[j].num<<" "<<std[j].name<<" "<<std[j].sex<<" "<<std[j].age<<endl;
                found = true;
                break;}
            }
            if(!found)
            {cout<<"No Answer!"<<endl;}
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-20 12:46
瘦嘟嘟右卫门:百度文库网盘的暑期也没约面吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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