#include <stdio.h>
#include <stdlib.h>
/*
问题描述:
输入任意时间,输出改时刻的下一秒:
例如输入2008年2月28日23时59分59秒,
输出为:2008年2月29日0时0分0秒。
输入一个时间,输出下一秒的时间。
例如输入2008年2月28日23时59分59秒,
输出为:2008年2月29日0时0分0秒。
*/
int isleapyear(int year);//闰年判断函数
//普通年(不能被100整除的年份)能被4整除的为闰年。(如2004年就是闰年,1999年不是闰年);
//世纪年(能被100整除的年份)能被400整除的是闰年。(如2000年是闰年,1900年不是闰年);
int main()
{
int year, month, day, hour, minute, second;
char s1[10], s2[10], s3[10], s4[10], s5[10], s6[10];
while(scanf("%d%2s%d%2s%d%2s%d%2s%d%2s%d%2s", &year, s1, &month, s2, &day, s3, &hour, s4, &minute, s5, &second, s6) != EOF)
//用char型数组来接收中文字符,在C语言中一个中文字符2个字节
{
printf("%d%s%d%s%d%s%d%s%d%s%d%s\n", year, s1, month, s2, day, s3, hour, s4, minute, s5, second, s6);
if(second == 59)
{
second = 0;
if(minute == 59)
{
minute = 0;
if(hour == 23)
{
hour = 0;
switch(month)
{
case 2:
{
if(isleapyear(year))
{
if(day == 29)
{
day =1;
month++;
}
else
{
day++;
}
}
else
{
if(day == 28)
{
day = 1;
month++;
}
}
break;
}
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if(day == 31)
{
day = 1;
if(month == 12)
{
month = 1;
year++;
}
else month++;
}
else day++;
break;
}
default://(4、6、9、11)
{
if(day == 30)
{
day = 1;
month++;
}
else day++;
break;
}
}
}
else hour++;
}
else minute++;
}
else second++;
printf("%d%s%d%s%d%s%d%s%d%s%d%s\n", year, s1, month, s2, day, s3, hour, s4, minute, s5, second, s6);
}
return 0;
}
int isleapyear(int year)//是否闰年判断函数,为闰年返回1,否则返回0
{
if(year%100)//不能被100整除,普通年
{
if(year%4) return 0;//不能被4整除,不是闰年
else return 1;
}
else //被100整除,世纪年
{
if(year%400) return 0;//不能被400整除,不是闰年
else return 1;
}
}
#include <stdlib.h>
/*
问题描述:
输入任意时间,输出改时刻的下一秒:
例如输入2008年2月28日23时59分59秒,
输出为:2008年2月29日0时0分0秒。
输入一个时间,输出下一秒的时间。
例如输入2008年2月28日23时59分59秒,
输出为:2008年2月29日0时0分0秒。
*/
int isleapyear(int year);//闰年判断函数
//普通年(不能被100整除的年份)能被4整除的为闰年。(如2004年就是闰年,1999年不是闰年);
//世纪年(能被100整除的年份)能被400整除的是闰年。(如2000年是闰年,1900年不是闰年);
int main()
{
int year, month, day, hour, minute, second;
char s1[10], s2[10], s3[10], s4[10], s5[10], s6[10];
while(scanf("%d%2s%d%2s%d%2s%d%2s%d%2s%d%2s", &year, s1, &month, s2, &day, s3, &hour, s4, &minute, s5, &second, s6) != EOF)
//用char型数组来接收中文字符,在C语言中一个中文字符2个字节
{
printf("%d%s%d%s%d%s%d%s%d%s%d%s\n", year, s1, month, s2, day, s3, hour, s4, minute, s5, second, s6);
if(second == 59)
{
second = 0;
if(minute == 59)
{
minute = 0;
if(hour == 23)
{
hour = 0;
switch(month)
{
case 2:
{
if(isleapyear(year))
{
if(day == 29)
{
day =1;
month++;
}
else
{
day++;
}
}
else
{
if(day == 28)
{
day = 1;
month++;
}
}
break;
}
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
if(day == 31)
{
day = 1;
if(month == 12)
{
month = 1;
year++;
}
else month++;
}
else day++;
break;
}
default://(4、6、9、11)
{
if(day == 30)
{
day = 1;
month++;
}
else day++;
break;
}
}
}
else hour++;
}
else minute++;
}
else second++;
printf("%d%s%d%s%d%s%d%s%d%s%d%s\n", year, s1, month, s2, day, s3, hour, s4, minute, s5, second, s6);
}
return 0;
}
int isleapyear(int year)//是否闰年判断函数,为闰年返回1,否则返回0
{
if(year%100)//不能被100整除,普通年
{
if(year%4) return 0;//不能被4整除,不是闰年
else return 1;
}
else //被100整除,世纪年
{
if(year%400) return 0;//不能被400整除,不是闰年
else return 1;
}
}