1083. List Grades (25)

柔情只为你懂 2022-05-30 02:26 242阅读 0赞

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

题目大意:

代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. struct node
  4. {
  5. char name[15];
  6. char id[15];
  7. int tag;
  8. }stud[110];
  9. int main()
  10. {
  11. int i,j,n,m,k,t,flag;
  12. char name[15],id[15];
  13. scanf("%d",&n);
  14. for(i=0;i<n;i++)
  15. {
  16. scanf("%s %s %d",name,id,&m);
  17. strcpy(stud[m].name,name);
  18. strcpy(stud[m].id,id);
  19. stud[m].tag=-1;
  20. }
  21. scanf("%d %d",&k,&t);
  22. flag=0;
  23. for(i=t;i>=k;i--)
  24. {
  25. if(stud[i].tag==-1)
  26. {
  27. printf("%s %s\n",stud[i].name,stud[i].id);
  28. flag=1;
  29. }
  30. }
  31. if(flag==0)
  32. {
  33. printf("NONE\n");
  34. }
  35. return 0;
  36. }

发表评论

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

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

相关阅读