PAT (Advanced Level) 1036. Boys vs Girls (25)

简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std;

const int maxn=100000;
struct X
{
    string name;
    string sex;
    string id;
    int c;
}s[maxn];
int n;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        cin>>s[i].name>>s[i].sex>>s[i].id>>s[i].c;
    int id1=-1,id2=-1;
    int Max=-1,Min=99999;
    for(int i=1;i<=n;i++)
        if(s[i].sex[0]=='F'&&s[i].c>Max) Max=s[i].c,id1=i;

    for(int i=1;i<=n;i++)
        if(s[i].sex[0]=='M'&&s[i].c<Min) Min=s[i].c,id2=i;

    if(id1==-1) printf("Absent\n");
    else cout<<s[id1].name<<" "<<s[id1].id<<endl;

    if(id2==-1) printf("Absent\n");
    else cout<<s[id2].name<<" "<<s[id2].id<<endl;

    if(id1==-1||id2==-1) printf("NA\n");
    else printf("%d\n",abs(s[id1].c-s[id2].c));

    return 0;
}

 

posted @ 2016-05-23 12:41  Fighting_Heart  阅读(222)  评论(0编辑  收藏  举报