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 (1≤T≤10).
The first line of each test case contains a single integer n -- the number of girls (1≤n≤50).
Each of the following n lines contains Ai, Si, the ith girl's age and name (3≤age≤80, 2≤length(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.
示例输入
5 21 liyuchun 18 fanbingbing 19 zhangziyi 22 liuyifei 20 liuyan 1 15 yangmi
示例输出
fanbingbing liuyifei yangmi yangmi
提示
来源
示例程序
#include <iostream>
#include <algorithm>using namespace std;struct stu
{int age;string name;
} girl[50];bool cmp(struct stu a , struct stu b )
{return a.age < b.age;
}int main()
{int n;int i;while(cin>>n){for(i=0; i<n; i++)cin>>girl[i].age>>girl[i].name;sort(girl,girl+n,cmp);cout<<girl[0].name<<" "<<girl[n-1].name<<endl;}return 0;
}