fzu训练赛14 H - Birthdates

H - Birthdates
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Write a program to identify the youngest person and the oldest person in a class.

 

Input

            The number nDescription: F:\Archive 2012\Thailand 2012\problemset\h_files\image019.gif in the first line determines the number of people in a class.  The following n lines contain person’s name and his/her birthdate. 

            The information in each line is of this format:

                                    personName  dd mm yyyy

            where  personName is a single word less than 15 letters,  dd mm yyyy are date, month and year of the birthdate.

            Suppose that no one has the same name or the same birthdate.

 

Output

            Print out 2 lines containing the name of youngest person and oldest person, respectively.

 

Sample Input

5

Mickey 1 10 1991

Alice 30 12 1990

Zipu 15 8 1993

Shanto 18 9 1990

Garfield 20 9 1990

 

Sample Output

Zipu

Shanto

 题目很简单,就是排序,用sort函数就行,自己写一个控制排序的函数就行。

#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
struct stt
{
	char aa[20];
	int day,mon,ye;
}node[300];
bool cmp(stt a,stt b) //控制排序顺序的函数
{ 
	if(a.ye>b.ye) 
	return true; 
    if(a.ye < b.ye) 
     return false; 
    if(a.ye==b.ye) 
    { 
     if(a.mon > b.mon) 
      return true; 
     if(a.mon < b.mon) 
      return false; 
     if(a.mon==b.mon) 
     { 
      if(a.day > b.day) 
       return true; 
      if(a.day < b.day) 
       return false; 
     } 
    } 
} 
int main()
{
	int n,i;
		int j,k;
	cin>>n;
	i=0;

	for(i=0;i<n;i++)
	{
		cin>>node[i].aa>>node[i].day>>node[i].mon>>node[i].ye;
	
	}


	sort(node,node+n,cmp);
	cout<<node[0].aa<<endl;
	cout<<node[n-1].aa<<endl;
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值