C++的问题 急求 求C++格式的回答 求大神帮助!!!
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 展开
#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;
}