Given a list of N student records with name, ID and grade. You is supposed to sort the records with respect to the grade in non-increasing order, and output those student records O F which the grades is in a given interval.
Input Specification:
Each input file contains the one test case. Each case was given in the following format:
NNAME[1] id[1] grade[1]name[2] id[2] grade[2] ... name[n] id[n] Grade[n]grade1 grade2
where Name[i] and id[i] were strings of no more than characters with no space, Grade[i] was an integer in [0, +], Grade 1 and Grade2 are the boundaries of the grade ' s interval. It is guaranteed, the grades is distinct.
Output Specification:
For each test case you should output the student records of which the grades is in the given interval [Grade1, Grade2] an D is in non-increasing order. Each student record occupies a line with the student's name and ID, separated by one space. If There is no student ' s grade in that interval, output "NONE" instead.
Sample Input 1:
4Tom CS000001 59Joe Math990112 89Mike CS991301 100Mary EE990830 9560 100
Sample Output 1:
Mike cs991301mary Ee990830joe Math990112
Sample Input 2:
2Jean AA980920 60Ann CS01 8090 95
Sample Output 2:
NONE
Source: >
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Stu
{
char name[11];
char id[11];
int grade;
};
vector<Stu> s,s1;
bool cmp(Stu a,Stu b) {
return a.grade > b.grade;
}
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
Stu temp;
scanf("%s %s %d", temp.name, temp.id, &temp.grade);
s.push_back(temp);
}
int low, high;
cin >> low >> high;
Span class= "KWD" >for ( int i = 0 I < n I ++) {
Span class= "KWD" >if ( s [ i . grade >= low && s [ i . grade <= high {
s1.push_back(s[i]);
}
}
if (s1.size() == 0) {
cout << "NONE";
return 0;
}
sort(s1.begin(), s1.end(), cmp);
Span class= "KWD" >for ( int i = 0 I < S1 size (); I ++) {
printf("%s %s\n", s1[i].name, s1[i].id);
}
return 0;
}
From for notes (Wiz)
1083. List Grades (25)