1. 程式人生 > >輸入時間求下一秒的時間(閒的沒事練了一下c語言)

輸入時間求下一秒的時間(閒的沒事練了一下c語言)


#include <iostream>
using namespace std;


int NextTime(int year,int month,int day,int hour,int minuter,int second)
{
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if (year<=0||month<=0||month>12||day<0||day>31||hour<0||hour>24||
minuter<0||minuter>=60||second<0||second>=60)
return 0;
if (year%400==0||year%100!=0&&year%4==0)
{
mon[1] = 29;
}
second=second+1;
if (second>=60)
{
second=0;
minuter++;
if (minuter>=60)
{
minuter=0;
hour++;
if (hour>=24)
{
hour = 0;
day++;
if (day>mon[month-1])
{
day=1;
month++;
if (month>12)
{
month=1;
year++;
}
}
}
}
}
  cout<<year<<"年"<<month<<"月"<<day<<"日"<<hour<<" 時"<<minuter<<"分"<<second<<"秒"<<endl;
  return 0;
}
int main ()
{
int year, month, day, hour, minuter, second;
while(cin>>year>>month>>day>>hour>>minuter>>second)
NextTime( year, month, day, hour,minuter, second);
return 0; 

}