PAT_A1083#List Grades
作者:互联网
Source:
Description:
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval.
Input Specification:
Each input file contains one test case. Each case is given in the following format:
N name[1] ID[1] grade[1] name[2] ID[2] grade[2] ... ... name[N] ID[N] grade[N] grade1 grade2
where
name[i]
andID[i]
are strings of no more than 10 characters with no space,grade[i]
is an integer in [0, 100],grade1
andgrade2
are the boundaries of the grade's interval. It is guaranteed that all the grades are distinct.
Output Specification:
For each test case you should output the student records of which the grades are in the given interval [
grade1
,grade2
] and are 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, outputNONE
instead.
Sample Input 1:
4 Tom CS000001 59 Joe Math990112 89 Mike CS991301 100 Mary EE990830 95 60 100
Sample Output 1:
Mike CS991301 Mary EE990830 Joe Math990112
Sample Input 2:
2 Jean AA980920 60 Ann CS01 80 90 95
Sample Output 2:
NONE
Keys:
- 模拟题
Attention:
- 先筛选,再排序,可以减少时间复杂度
Code:
1 /* 2 Data: 2019-07-13 10:38:02 3 Problem: PAT_A1083#List Grades 4 AC: 14:45 5 6 题目大意: 7 按成绩递减打印给定区间内学生的成绩 8 输入: 9 第一行给出,人数N 10 接下来N行,姓名,ID,成绩 11 最后一行给出,[g1,g2] 12 输出: 13 成绩递减,打印姓名和ID 14 */ 15 #include<cstdio> 16 #include<string> 17 #include<vector> 18 #include<iostream> 19 #include<algorithm> 20 const int M=1e3; 21 using namespace std; 22 struct node 23 { 24 string name,id; 25 int grade; 26 }info[M]; 27 vector<node> ans; 28 29 bool cmp(node a, node b) 30 { 31 return a.grade > b.grade; 32 } 33 34 int main() 35 { 36 #ifdef ONLINE_JUDGE 37 #else 38 freopen("Test.txt", "r", stdin); 39 #endif 40 41 int n,g1,g2; 42 scanf("%d", &n); 43 for(int i=0; i<n; i++) 44 cin >> info[i].name >> info[i].id >> info[i].grade; 45 scanf("%d%d", &g1,&g2); 46 for(int i=0; i<n; i++) 47 if(info[i].grade>=g1 && info[i].grade<=g2) 48 ans.push_back(info[i]); 49 sort(ans.begin(),ans.end(),cmp); 50 if(ans.size() == 0) 51 printf("NONE\n"); 52 for(int i=0; i<ans.size(); i++) 53 cout << ans[i].name << " " << ans[i].id << endl; 54 55 return 0; 56 }
标签:int,name,A1083,List,grade,Grades,student,include,ID 来源: https://www.cnblogs.com/blue-lin/p/11179785.html