|
- #include<bits/stdc++.h>
- #include<conio.h>
- #include <windows.h>
- using namespace std;
- int z;
- char ch;
- struct ty
- {
- int a;
- int f;
- int s;
- int y;
- int m;
- int d;
- string xg;
- }t={19,6,30,2022,10,20};
- 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);
- };
- string CaculateWeekDay(int y,int m, int d)
- {
- string w;
- 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: w="星期一"; break;
- case 1: w="星期二\n"; break;
- case 2: w="星期三\n"; break;
- case 3: w="星期四\n"; break;
- case 4: w="星期五\n"; break;
- case 5: w="星期六\n"; break;
- case 6: w="星期日\n"; break;
- }
- return w;
- }
- int sth(int y)
- {
- if((y%4==0)&&y%100!=0)
- {
- z=1;
- }
- else if(y%400==0)
- {
- z=1;
- }
- else
- z=0;
- return z;
- }
- int main()
- {
- system("color 3F");
- HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
- int n[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,
- 31,29,31,30,31,30,31,31,30,31,30,31};
- while(1)
- {
- t.s++;
- if(t.s==60)
- {
- t.s=0;
- t.f++;
- if(t.f==60)
- {
- t.f=0;
- t.a++;
- if(t.a==24)
- {
- t.a=1;
- t.d++;
- if(t.d==n[sth(t.y)][t.m-1]+1)
- {
- t.d=1;
- t.m++;
- if(t.m==13)
- {
- t.m=1;
- t.y++;
- }
- }
- }
- }
- }
-
- t.xg=CaculateWeekDay(t.y,t.m,t.d);
- cout<<t.y<<"年"<<t.m<<"月"<<t.d<<"日"<<setw(2)<<t.a<<":"<<setw(2)<<t.f<<":"<<setw(2)<<t.s<<' '<<t.xg<<endl;
- Sleep(900);
- gotoxy(hout,0,0);
- if(kbhit())
- {
- ch=getch();
- if(ch='w')
- {
- gotoxy(hout,0,0);
- cout<<" ";
- gotoxy(hout,0,0);
- cin>>t.y;
- gotoxy(hout,6,0);
- cout<<" ";
- gotoxy(hout,6,0);
- cin>>t.m;
- gotoxy(hout,10,0);
- cout<<" ";
- gotoxy(hout,10,0);
- cin>>t.d;
- gotoxy(hout,14,0);
- cout<<" ";
- gotoxy(hout,14,0);
- cin>>t.a;
- gotoxy(hout,17,0);
- cout<<" ";
- gotoxy(hout,17,0);
- cin>>t.f;
- gotoxy(hout,20,0);
- cout<<" ";
- gotoxy(hout,20,0);
- cin>>t.s;
- gotoxy(hout,0,0);
- }
- }
-
- }
- return 0;
- }
复制代码 |
|