结构体

学生查询

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

#include<bits/stdc++.h>
using namespace std;
struct stu {
    int num;
    string name;
    string sex;
    int age;
};

vector<stu> sign(int n) {
    vector<stu> arr;
    for (int i = 0; i < n; i++) {
        stu temp;
        cin >> temp.num >> temp.name >> temp.sex >> temp.age;
        arr.push_back(temp);
    }
    return arr;
}

int main() {
    int m;
    cin >> m; //sample nums
    for (int i = 0; i < m; i++) {
        int n;
        cin >> n; //stu nums

        vector<stu>stuarr = sign(n);//sign

        int x;
        cin >> x;
        for (int i = 0; i < n; i++) {
            stu t = stuarr[i];
            if (t.num == x) { //find
                cout << t.num << ' ' << t.name << ' ' << t.sex << ' ' << t.age << '\n';
            }
        }
    }
}

全部评论

相关推荐

04-12 13:42
江南大学 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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