该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#define START_YEAR 1970;
typedef struct
{
int year;
char month;
char day;
char hour;
char minute;
long second;
}kalendartypedef;
long write_data(int year,char month,char day,char hour,char minute,long second);
long kalendar(kalendartypedef*kalendarstruct);
struct kalendartypedef processclock_data(long clockdata);
void printf_clock_NOW(kalendartypedef * kalendarstruct);
int main()
{
int a,b,c,d,e;
long f;
while(1){
scanf("%d%d%d%d%d%ld",&a,&b,&c,&d,&e,&f);
//(processclock_data(write_data(a,b,c,d,e,f)))
kalendartypedef sendcolckdata=processclock_data(write_data(a,b,c,d,e,f));
printf_clock_NOW(&sendcolckdata);
//printf("%ld\n",processclock_data(write_data(a,b,c,d,e,f))))
//printf("%ld\n",write_data(a,b,c,d,e,f))
system("pause");
return 0;
}
long write_data(int a,char b,char c,char d,char e,long f)
{
long num;
kalendartypedef kalendarstructure;
kalendarstructure.year=a;
kalendarstructure.month=b;
kalendarstructure.day=c;
kalendarstructure.hour=d;
kalendarstructure.minute=e;
kalendarstructure.second=f;
num=kalendar(&kalendarstructure);
return num;
}
long kalendar(kalendartypedef*kalendarstruct) //24小时制
{
char leapyear=0;//闰
char commonyear=0;//平
int temp=START_YEAR;
for(temp;tempyear;temp++)
{
if((temp%4==0&&temp%100!=0)||temp%400==0)leapyear++;
else commonyear++;
}
//printf("1970-2017有: %d个平年%d个闰年\n",commonyear,leapyear);
long tolsec=leapyear*366*24*60*60+commonyear*365*24*60*60;
//printf("总共有: %ld秒\n",tolsec);
if(kalendarstruct->year%4==0&&kalendarstruct->year%100!=0&&kalendarstruct->year%400==0)leapyear=1;
else leapyear=0;
//printf("2018年是: %ld年1是闰年\n",leapyear);
if(commonyear)
{
int tempday=0;
for(temp=kalendarstruct->month-1;temp>0;temp--)
{
switch(temp)
{
case 1: tempday+=31;break;
case 2: if(leapyear==0)tempday+=28;
else tempday+=29;break;
case 3: tempday+=31;break;
case 4: tempday+=30;break;
case 5: tempday+=31;break;
case 6: tempday+=30;break;
case 7: tempday+=31;break;
case 8: tempday+=31;break;
case 9: tempday+=30;break;
case 10: tempday+=31;break;
case 11: tempday+=30;break;
}
}
//printf("2018截止12月27日共: %ld天\n",tempday);
tempday+=kalendarstruct->day-1;
//printf("2018截止12月27日共: %ld天\n",tempday);
tolsec+=tempday*24*60*60;
tolsec+=kalendarstruct->second+kalendarstruct->minute*60+kalendarstruct->hour*60*60;
}
return tolsec;
}
kalendartypedef processclock_data(long clockdata)
{
kalendartypedef clockdata_structure;
long today_sec_tol=clockdata%8640;
int tol_day=clockdata/8640;
int start_year=START_YEAR;
//clockdata-=today_sec_tol;
char temp1=0,temp2=0;
while(tol_day>365)
{
start_year++;
if((start_year%4==0&&start_year%100!=0)||start_year%400==0){tol_day-=366;temp1++;}
else {tol_day-=365;temp2++;}
}
tol_day-=(temp1*366+temp2*365);
switch(1)
{
case 1:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=1;clockdata_structure.day=tol_day;break;}
case 2:if((start_year%4==0&&start_year%100!=0)||start_year%400==0)
{
if(tol_day>29)tol_day-=29;
else {clockdata_structure.month=2;clockdata_structure.day=tol_day;break;}
}
else if(tol_day>28)tol_day-=28;
else {clockdata_structure.month=2;clockdata_structure.day=tol_day;break;}
case 3:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=3;clockdata_structure.day=tol_day;break;}
case 4:if(tol_day>30)tol_day-=30;else {clockdata_structure.month=4;clockdata_structure.day=tol_day;break;}
case 5:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=5;clockdata_structure.day=tol_day;break;}
case 6:if(tol_day>30)tol_day-=30;else {clockdata_structure.month=6;clockdata_structure.day=tol_day;break;}
case 7:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=7;clockdata_structure.day=tol_day;break;}
case 8:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=8;clockdata_structure.day=tol_day;break;}
case 9:if(tol_day>30)tol_day-=30;else {clockdata_structure.month=9;clockdata_structure.day=tol_day;break;}
case 10:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=10;clockdata_structure.day=tol_day;break;}
case 11:if(tol_day>30)tol_day-=30;else {clockdata_structure.month=11;clockdata_structure.day=tol_day;break;}
case 12:if(tol_day>31)tol_day-=31;else {clockdata_structure.month=12;clockdata_structure.day=tol_day;break;}
}
clockdata_structure.hour=today_sec_tol/3600;
clockdata_structure.minute=today_sec_tol%3600/60;
clockdata_structure.second=today_sec_tol%3600%60;
clockdata_structure.year=start_year;
return clockdata_structure;
}
void printf_clock_NOW(kalendartypedef * kalendarstruct)
{
printf("现在是%d年",kalendarstruct->year);
printf("%d月",kalendarstruct->month);
printf("%d日",kalendarstruct->day);
printf("%d点",kalendarstruct->hour);
printf("%d分",kalendarstruct->minute);
printf("%ld秒",kalendarstruct->second);
}