|
- #include<bits/stdc++.h>
- #include <windows.h>
- using namespace std;
- int a;
- int hour,minute,second,year,month,day,week;
- int month1[2][12]={32,29,32,31,32,31,32,32,31,32,31,32,
- 32,30,32,31,32,31,32,32.31,32,31,32};
- void gotoxy(HANDLE hout, int x, int y);
- void gotoxy(HANDLE hout, int x, int y){
- COORD pos;
- pos.X = x;
- pos.Y = y;
- SetConsoleCursorPosition(hout, pos);
- };
- int pingrun()
- {
- if(year%4==0)
- {
- if(year%100==0)
- {
- if(year%400==0)
- a=1;
- else
- a=0;
- }
- else
- a=1;
- }
- else
- a=0;
- return a;
- }
- void CaculateWeekDay(int y,int m, int d)
- {
- if(m==1||m==2) {
- m+=12;
- y--;
- }
- int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
- switch(iWeek)
- {
- case 0: printf("星期一\n"); break;
- case 1: printf("星期二\n"); break;
- case 2: printf("星期三\n"); break;
- case 3: printf("星期四\n"); break;
- case 4: printf("星期五\n"); break;
- case 5: printf("星期六\n"); break;
- case 6: printf("星期日\n"); break;
- }
- }
- int main()
- {
- HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
- cin>>year;
- cout<<"年";
- cin>>month;
- cout<<"月";
- cin>>day;
- cout<<"日"<<endl;
- //cout<<"星期";
-
- cin>>week;
- cin>>hour;
- cout<<":";
- cin>>minute;
- cout<<":";
- cin>>second;
-
- CaculateWeekDay(year,month,day);
- for(;;second++)
- {
- if(second==60)
- {
- minute+=1;
- second=0;
- if(minute==60)
- {
- hour+=1;
- minute=0;
- if(hour==24)
- {
- hour=0;
- second=0;
- minute=0;
- day+=1;
- hour=0;
- if(day==month1[pingrun()][month-1])
- {
- month+=1;
- day=1;
- if(month==13)
- {
- year+=1;
- month=1;
- }
- }
- }
- }
- }
- else
- {
- cout<<setw(4)<<year<<"年"<<setw(2)<<month<<"月"<<setw(2)<<day<<"日"<<'\n';
- cout<<setw(2)<<hour<<":"<<setw(2)<<minute<<":"<<setw(2)<<second<<'\n';
- Sleep(100);
- gotoxy(hout,0,12);
- }
- }
-
- return 0;
- }
复制代码
|
|