15省赛A-结构体排序

来源:互联网 发布:vb for循环 编辑:程序博客网 时间:2024/05/21 06:57

周末要去QTECH打酱油,现在补补省赛题,攒攒人品。

#include<iostream>#include<algorithm>#include<stdio.h>//#define fileusing 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;}


0 0
原创粉丝点击