C++的问题 急求 求C++格式的回答 求大神帮助!!!

介绍:Defineastructthatcontainstheyear,month,andday,representingthebirthdateofastudent.T... 介绍:
Define a struct that contains the year, month, and day, representing the birth date of a student. Then find out the birth date of a group of students who came second.
Requirement: You must use a struct to store the birth date. You cannot use other types of data structures.
It is required that the entire process of the program must use struct for input, access and output of the birth date.

输入:
Input t in the first line to indicate t birth dates.
Input three integers on each line, indicating the year, month, and day.
Input t instances in turn.

输出:
Output the second oldest birth date in the format of year-month-day.

输入例子:
6
1980 5 6
1981 8 3
1980 3 19
1980 5 3
1983 9 12
1981 11 23

输出例子:
1980-5-3
展开
 我来答
小黑哎啊
科技发烧友

2020-07-14 · 智能家居/数码/手机/智能家电产品都懂点
知道大有可为答主
回答量:1642
采纳率:74%
帮助的人:343万
展开全部

#include<iostream>

using namespace std;

struct st{

int year;

int month;

int day;

};

int main()

{

struct st s[111],x;

int t,i,j;

cin>>t;

for(i=0;i<t;i++)

cin>>s[i].year>>s[i].month>>s[i].day;

for(i=0;i<t;i++)

for(j=0;j<t-i-1;j++)

if(s[j].year>s[j+1].year)//年份不等;年份小的往前排 1980排在1981前面 

{

x=s[j];//结构体整体交换 

s[j]=s[j+1];

s[j+1]=x;

}

else if(s[j].year==s[j+1].year)//年份相等的 

{

if(s[j].month>s[j+1].month)//月份小的往前排 ,5排在6前面 

{

x=s[j];//结构体整体交换 

s[j]=s[j+1];

s[j+1]=x;

}

else if(s[j].month==s[j+1].month)//月份相等的 

{

if(s[j].day>s[j+1].day)//日期小的往前排,25排在30前面 

{

x=s[j];//结构体整体交换 

s[j]=s[j+1];

s[j+1]=x;

}

}

}

cout<<s[1].year<<"-"<<s[1].month<<"-"<<s[1].day;//输出结构体数组s的第二个元素 

return 0;

}

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式