文章

61

粉丝

98

获赞

17

访问

16.3k

头像
查找学生信息2 题解:c++ map实现
P1476 清华大学机试题
发布于2024年3月16日 09:23
阅读数 168

#include<bits/stdc++.h>
using namespace std ;

struct node {
    string id ;
    string name ;
    string sex ;
    string age ;
} ;

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

    for(int i = 0 ;i < n ;i++){
        cin >>  tmp.id >> tmp.name >> tmp.sex >> tmp.age ;
        students[tmp.id] = tmp ;
    }

    int m ;
    string seach_id ;
    map<string, node>::iterator it;
    cin >> m ;
    for(int i  = 0 ;i < m ;i++){
        cin >> seach_id ;
        it = students.find(seach_id);
        if(it != students.end()){
            cout << it->second.id << " " << it->second.name << " " << it->second.sex << " " <<it->second.age << endl ;
        }else cout << "No Answer!" << endl;
    }

    return 0 ;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发