解题思路:
注意事项:
参考代码:
#include<stdio.h>
struct date
{
int year;
int month;
int day;
};
int main()
{
struct date m[10000];
int i, j, k=0;
while (scanf_s("%d/%d/%d", &m[k].month, &m[k].day, &m[k].year) != EOF)
{
k++;
}
for(i=0;i<k-1;i++)
for (j = 0; j < k - i - 1; j++)
{
if (m[j].year > m[j + 1].year)
{
struct date temp;
temp = m[j];
m[j] = m[j + 1];
m[j + 1] = temp;
}
else if (m[j].year == m[j + 1].year)
{
if (m[j].month > m[j + 1].month)
{
struct date temp;
temp = m[j];
m[j] = m[j + 1];
m[j + 1] = temp;
}
else if (m[j].month == m[j + 1].month)
{
if (m[j].day > m[j + 1].day)
{
struct date temp;
temp = m[j];
m[j] = m[j + 1];
m[j + 1] = temp;
}
}
}
}
for (i = 0; i < k; i++)
{
if (m[i].month < 10)printf("0%d/", m[i].month);
else printf("%d/", m[i].month);
if (m[i].day < 10)
printf("0%d/%d", m[i].day,m[i].year);
else
printf("%d/%d\n", m[i].day,m[i].year);
}
return 0;
}
0.0分
0 人评分