首页 > 其他 > 详细

PAT 1083

时间:2014-11-08 21:59:28      阅读:188      评论:0      收藏:0      [点我收藏+]
 1 #include <vector>
 2 #include <algorithm>
 3 #include <string>
 4 #include <iostream>
 5 
 6 using namespace std;
 7 
 8 struct Student{
 9     int grade;
10     string name;
11     string id;
12 };
13 
14 bool compare(const Student &s1, const Student &s2){
15     return s1.grade > s2.grade;
16 }
17 
18 int main(){
19     int N;
20     cin >> N;
21 
22     vector<Student> students;
23 
24     for (int i = 0; i < N; i++){
25         Student s;
26         cin >> s.name >> s.id >> s.grade;
27 
28         students.push_back(s);
29     }
30 
31     int low, high;
32     cin >> low >> high;
33 
34     sort(students.begin(), students.end(), compare);
35     bool none = true;
36     for (int i = 0; i < students.size(); i++){
37         if (students[i].grade < low)
38             break;
39         if (students[i].grade > high)
40             continue;
41 
42         none = false;
43         cout << students[i].name << " " << students[i].id << endl;
44     }
45 
46     if (none)
47         cout << "NONE" << endl;
48 
49     return 0;
50 }

 

PAT 1083

原文:http://www.cnblogs.com/EpisodeXI/p/4084073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!