愿尔安然无恙


私信TA

用户名:H2130819045

访问量:12346

签 名:

向往星辰大海,喜欢落日晚风。

等  级
排  名 59
经  验 10466
参赛次数 16
文章发表 56
年  龄 20
在职情况 学生
学  校 贺州学院
专  业 软件工程

  自我简介:

不想改bug ^_^

TA的其他文章

参考代码:

#include<iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef struct Time//定义结构体
{
	int year;
	int month;
	int day; 
}stu;
int cmp(stu a,stu b)//定义排序规则
{
	if(a.year!=b.year)
	{
		return a.year<b.year;
	}
	if(a.month!=b.month)
	{
		return a.month<b.month;
	}
	if(a.day!=b.day)
	{
		return a.day<b.day;
	}
}
int main()
{ 
	char ch;
	int year,month,day,k=0; 
	stu s[200];
	while(cin>>s[k].month>>ch>>s[k].day>>ch>>s[k].year)//以EOF结尾
	{
		k++;
	}
	sort(s,s+k,cmp);
	for(int i=0;i<k;i++)
	{
		cout<<setw(2)<<setfill('0')<<s[i].month<<'/'<<setw(2)<<setfill('0')<<s[i].day<<'/'<<setw(4)<<setfill('0')<<s[i].year;
		cout<<endl;
	}
}


 

0.0分

2 人评分

  评论区