题解 | #最小年龄的3个职工#

最小年龄的3个职工

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

#include <bits/stdc++.h>
using namespace std;
struct stuff{
    int num,age;
    string name;
};
bool cmp(stuff A,stuff B)
{
    if(A.age!=B.age) return A.age<B.age;
    else return A.num<B.num;
}
int main() {
    int n;
    while (cin >> n) {
        stuff stu[n]; 
        for(int i=0;i<n;i++) cin>>stu[i].num>>stu[i].name>>stu[i].age;
        sort(stu,stu+n,cmp);
        for(int i=0;i<3;i++) cout<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].age<<endl;   
    }
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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