15省賽A-結構體排序
阿新 • • 發佈:2019-01-06
週末要去QTECH打醬油,現在補補省賽題,攢攢人品。
#include<iostream> #include<algorithm> #include<stdio.h> //#define file using namespace std; struct data{ double high; double weight; }; bool cmp(data a,data b) { return a.high<b.high; } int main() { #ifdef file freopen("test.in","r",stdin); freopen("test.out","w",stdout); #endif // file data man[200]; int t; cin>>t; while(t--) { int n; cin>>n; for(int i=0;i<n;i++) { cin>>man[i].high>>man[i].weight; } sort(man,man+n,cmp); double red=0,blue=0; for(int i=0;i<n;i++) { if(i%2==0) red+=man[i].weight; else blue+=man[i].weight; } if(red>blue) puts("red"); else if(red<blue) puts("blue"); else if(red==blue) puts("fair"); } return 0; }