Description:PAT A1083 List Grades (25 分)
input Specification: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.
Output Specification:Each input file contains one test case. Each case is given in the following format:
Nname[1] ID[1] grade[1]name[2] ID[2] grade[2]... ...name[N] ID[N] grade[N]grade1 grade2where
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.
Sample input 1: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 Output 1:4Tom CS000001 59Joe Math990112 89Mike CS991301 100Mary EE990830 9560 100
Sample input 2:Mike CS991301Mary EE990830Joe Math990112
Sample Output 2:2Jean AA980920 60Ann CS01 8090 95
Keys: 模拟题 Attention: 先筛选,再排序,可以减少时间复杂度 Code:NONE
1 /* 2 Data: 2019-07-13 10:38:02 3 Problem: PAT_A1083#List Grades 4 AC: 14:45 5 6 题目大意: 7 按成绩递减打印给定区间内学生的成绩 8 输入: 9 第一行给出,人数N10 接下来N行,姓名,ID,成绩11 最后一行给出,[g1,g2]12 输出:13 成绩递减,打印姓名和ID14 */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 node23 {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_JUDGE37 #else38 freopen("Test.txt","r",stdin);39 #endif40 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 }总结
以上是内存溢出为你收集整理的PAT_A1083#List Grades全部内容,希望文章能够帮你解决PAT_A1083#List Grades所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)