sdut Find a girl friend(结构体的二级排序)

来源:互联网 发布:c高性能编程 pdf 编辑:程序博客网 时间:2024/04/29 02:04

Find a girl friend

Time Limit: 1000ms   Memory limit: 262144K  有疑问?点这里^_^

题目描述

CC wants to find a girl friend, he knows each girl's age and name in his class, and each girl’s age is different..

Now he wants to know the youngest girl's name and the eldest girl’s name, can you help him?

输入

 

Input will consist of T test cases (1T10).

The first line of each test case contains a single integer n -- the number of girls (1n50).

Each of the following n lines contains Ai, Si, the ith girl's age and name (3≤age≤80, 2length(name)≤20), separated by exactly one space. 

Each girl’s name consists of between 2 and 20 lowercase letters.

输出

 

For each test case, output the youngest girl's name and the eldest girl's name, seperated by exactly one space.

示例输入

521 liyuchun18 fanbingbing19 zhangziyi22 liuyifei20 liuyan115 yangmi

示例输出

fanbingbing liuyifeiyangmi yangmi
 
这个题目主要是找到身高的最大值和最小值输出姓名,分别用空格隔开,代码如下:
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;struct node{    int h;    char n[100];}q[10000];bool cmp(node a,node b){    return a.h < b.h;}int main(){    int n;    int i,j;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i<n;i++)        {            cin>>q[i].h>>q[i].n;        }        sort(q,q + n,cmp);        cout<<q[0].n<<" "<<q[n-1].n<<endl;    }    return 0;}

0 0
原创粉丝点击