PAT 甲级 1083 List Grades (25 分)

﹏ヽ暗。殇╰゛Y 2024-02-19 21:33 156阅读 0赞

1083 List Grades (25 分)

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:

  1. N
  2. name[1] ID[1] grade[1]
  3. name[2] ID[2] grade[2]
  4. ... ...
  5. name[N] ID[N] grade[N]
  6. grade1 grade2

where name[i] and ID[i] are strings of no more than 10 characters with no space, grade[i] is an integer in [0, 100], grade1 and grade2 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, output NONE instead.

Sample Input 1:

  1. 4
  2. Tom CS000001 59
  3. Joe Math990112 89
  4. Mike CS991301 100
  5. Mary EE990830 95
  6. 60 100

Sample Output 1:

  1. Mike CS991301
  2. Mary EE990830
  3. Joe Math990112

Sample Input 2:

  1. 2
  2. Jean AA980920 60
  3. Ann CS01 80
  4. 90 95

Sample Output 2:

  1. NONE
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstdio>
  5. #include<cstring>
  6. using namespace std;
  7. struct node{
  8. string name,id;
  9. int grade,f;
  10. node(){
  11. this->grade=-1;
  12. this->f=0;
  13. }
  14. };
  15. node a[102];
  16. void init()
  17. {
  18. for(int i=1;i<=100;i++)
  19. {
  20. a[i].grade=-1;
  21. a[i].f=0;
  22. }
  23. }
  24. int cmp(node a,node b)
  25. {
  26. return a.grade>b.grade;
  27. }
  28. int main()
  29. {
  30. int n,i,j,t,min_g,max_g,flag=0;
  31. string tn,tid;
  32. scanf("%d",&n);
  33. init();
  34. for(i=0;i<n;i++)
  35. {
  36. cin>>tn>>tid>>t;
  37. a[t].name=tn;
  38. a[t].id=tid;
  39. a[t].f=1;
  40. }
  41. cin>>min_g>>max_g;
  42. for(i=max_g;i>=min_g;i--)
  43. {
  44. if(a[i].f)
  45. {
  46. flag=1;
  47. cout<<a[i].name<<" "<<a[i].id<<endl;
  48. }
  49. }
  50. if(!flag)
  51. cout<<"NONE"<<endl;
  52. return 0;
  53. }

发表评论

表情:
评论列表 (有 0 条评论,156人围观)

还没有评论,来说两句吧...

相关阅读