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

本题描述了如何帮助CC找到班上年龄最小和最大的女生的名字。输入包含多个测试用例,每个用例首先给出女生数量,随后是各女生的年龄及名字。通过排序算法确定年龄最小和最大的女生,并输出其名字。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
#include <cstdio>
#include <string>
using namespace std;
struct node
{
    int h;
    string n;
}q[10000];

bool cmp(node a,node b)
{
    return a.h<b.h;
}

int main()
{
    int n;
    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;
}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值