Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
EDITORIAL
- Ideas analysis
- Student structured array package meta information
- An array of structures vector v [4] category candidates package 4
- cmp function, time-consuming than
- Sort according to first sort out, and then follow sorted by Germany, according to the last sort Caifen
- Output meets criteria -
- Student structured array package meta information
- Simple title, 20 minutes a title
Test Case
-
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 Code
-
#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; }