1083. List Grades (25)

Source: Internet
Author: User


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: >  
  
 
  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <string>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8. struct Stu
  9. {
  10. char name[11];
  11. char id[11];
  12. int grade;
  13. };
  14. vector<Stu> s,s1;
  15. bool cmp(Stu a,Stu b) {
  16. return a.grade > b.grade;
  17. }
  18. int main(void) {
  19. int n;
  20. cin >> n;
  21. for (int i = 0; i < n; i++) {
  22. Stu temp;
  23. scanf("%s %s %d", temp.name, temp.id, &temp.grade);
  24. s.push_back(temp);
  25. }
  26. int low, high;
  27. cin >> low >> high;
  28. Span class= "KWD" >for ( int i = 0 I < n I ++) {
  29. Span class= "KWD" >if ( s [ i . grade >= low && s [ i . grade <= high {
  30. s1.push_back(s[i]);
  31. }
  32. }
  33. if (s1.size() == 0) {
  34. cout << "NONE";
  35. return 0;
  36. }
  37. sort(s1.begin(), s1.end(), cmp);
  38. Span class= "KWD" >for ( int i = 0 I < S1 size (); I ++) {
  39. printf("%s %s\n", s1[i].name, s1[i].id);
  40. }
  41. return 0;
  42. }



From for notes (Wiz)

1083. List Grades (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.