1083. List Grades 解析

来源:互联网 发布:地产销售数据报告范文 编辑:程序博客网 时间:2024/06/13 07:34

输出给出范围内,学生的名次,直接排序,然后在范围内的输出。

#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;struct stu {string name;string id;int grade;bool operator > (const stu s2) {return grade > s2.grade;}};stu list[200];int n, low, high;int sum = 0;bool cmp(stu s1, stu s2) {return s1 > s2;}int main() {cin >> n;for (int i = 0; i < n; i++) {cin >> list[i].name >> list[i].id >> list[i].grade;}sort(list, list + n, cmp);cin >> low >> high;vector <stu> ans;for (int i = 0; i < n; i++) {if (list[i].grade >= low && list[i].grade <= high) {ans.push_back(list[i]);}}if (ans.size() == 0) {cout << "NONE" << endl;return 0;}else {for (int i = 0; i < ans.size(); i++) {cout << ans[i].name << " " << ans[i].id << endl;}}return 0;}


0 0