1019: 谁是老二(结构体)

题目描述
定义一个结构体,包含年月日,表示一个学生的出生日期。然后在一群学生的出生日期中找出谁的出生日期排行第二

要求:出生日期的存储必须使用结构体,不能使用其他类型的数据结构。

要求程序全过程对出生日期的输入、访问、输出都必须使用结构。

输入
第一行输入t表示有t个出生日期

每行输入三个整数,分别表示年、月、日

依次输入t个实例

输出
输出排行第二老的出生日期,按照年-月-日的格式输出

样例输入
6
1980 5 6
1981 8 3
1980 3 19
1980 5 3
1983 9 12
1981 11 23
样例输出
1980-5-3
提示

#include<bits/stdc++.h>
using namespace std;
struct node{
	int year;
	int month;
	int day;
};
int comp(const node &s1,const node &s2)
	{
		if(s1.year==s2.year&&s1.month!=s2.month){
			return s1.month<s2.month;
		}
		else if(s1.year==s2.year&&s1.month==s2.month&&s1.day!=s2.day)
		{return s1.day<s2.day;}
		else return s1.year<s2.year; 
}
int main(){
	int t;
	cin>>t;
	node stu[t];
	node temp;
	for(int i=0;i<t;i++){
	int a,b,c;
	cin>>a>>b>>c;
	stu[i].year=a;
	stu[i].month=b;
	stu[i].day=c;
}
sort(stu,stu+t,comp);
cout<<stu[1].year<<"-"<<stu[1].month<<"-"<<stu[1].day;	
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谁的BUG最难改

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值