写在前面
- 思路分析
- 结构体数组封装学生元信息
- 结构体数组vector v[4]封装4类考生
- cmp函数,较耗费时间
- 排序先按照总分排序,然后按照德分排序,最后按照才分排序
- 输出符合条件的结果~
- 结构体数组封装学生元信息
- 题目简单,20分钟a题
测试用例
-
input: 14 60 80 10000001 64 90 10000002 90 60 10000011 85 80 10000003 85 80 10000004 80 85 10000005 82 77 10000006 83 76 10000007 90 78 10000008 75 79 10000009 59 90 10000010 88 45 10000012 80 100 10000013 90 99 10000014 66 60 output: 12 10000013 90 99 10000012 80 100 10000003 85 80 10000011 85 80 10000004 80 85 10000007 90 78 10000006 83 76 10000005 82 77 10000002 90 60 10000014 66 60 10000008 75 79 10000001 64 90
ac代码
-
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct node { int num, de, cai; }; int cmp(node a,node b) { if((a.de + a.cai) != (b.de+b.cai)) return (a.de + a.cai) > (b.de+b.cai); else if(a.de != b.de) return a.de>b.de; else return a.num<b.num; } int main() { int n, low, high; scanf("%d %d %d", &n, &low, &high); vector<node> v[4]; node tmp; int total = n; for(int i=0; i<n; i++) { scanf("%d %d %d", &tmp.num,&tmp.de,&tmp.cai); if(tmp.de < low || tmp.cai < low) total--; else if(tmp.de >= high && tmp.cai >= high) v[0].push_back(tmp); else if(tmp.de >= high && tmp.cai<high) v[1].push_back(tmp); else if(tmp.de < high && tmp.cai < high && tmp.de >= tmp.cai) v[2].push_back(tmp); else v[3].push_back(tmp); } printf("%d\n", total); for(int i=0; i<4; i++) { sort(v[i].begin(), v[i].end(), cmp); for(int j=0; j<v[i].size(); j++) printf("%d %d %d\n", v[i][j].num, v[i][j].de, v[i][j].cai); } return 0; }