【PAT甲级 结构体排序水题】1083 List Grades (25 分)

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

struct Stu{
    
    
    string name, id;
    int grade;
};
int N, low, high;
vector<Stu> stu;

int main() {
    
    
    cin >> N;
    stu.resize(N);
    for(int i = 0;i < N;++i)
        cin >> stu[i].name >> stu[i].id >> stu[i].grade;
    cin >> low >> high;
    for(auto it = stu.begin();it != stu.end();){
    
    
        if(it->grade < low || it->grade > high) it = stu.erase(it);
        else it++;
    }
    sort(stu.begin(), stu.end(), [](Stu a, Stu b){
    
    return a.grade > b.grade;});
    if(stu.size() == 0)  cout << "NONE\n";
    else for(Stu s: stu) cout << s.name << " " << s.id << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/MYMarcoreus/article/details/114325655
今日推荐