1083. List Grades (25)

the problem is from PAT,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1083

and the source code is as followed.

/*
firstly: sort the array using the algorithm "sort"
secondly: traverse all the possible answer and find the most suitable one.
*/
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

struct record
{
    string name;
    string id;
    int grade;
};

bool cmp(record x,record y)
{
    return x.grade > y.grade;
}

int main()
{
    int n;
    record temp;
    vector<record> v;
    cin>>n;
    while (n--)
    {
        cin>>temp.name>>temp.id>>temp.grade;
        v.push_back(temp);
    }
    int low,high;
    cin>>low>>high;

    sort(v.begin(),v.end(),cmp);
    int count = 0;
    for (int i = 0; i < v.size(); i++)
    {
        
        if (v[i].grade>=low && v[i].grade <= high)
        {
            cout<<v[i].name<<" "<<v[i].id<<endl;
            count += 1;
        }
    }
    if (count == 0)
    {
        cout<<"NONE"<<endl;
    }
    
}

this one is easy.and it doesn’t need to talk too much. If there are something to be noticed ,

maybe i think we should notice the boundery.

原文地址:https://www.cnblogs.com/maverick-fu/p/3969358.html