|
#include<bits/stdc++.h>
#include <windows.h>
using namespace std;
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 i[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int rn(int t)
{
if (t % 4 == 0)
{
if (t % 100 == 0)
{
// // 这里如果被 400 整除是闰年
if (t % 400 == 0)
i[1]=29;
else
i[1]=28;
}
else
i[1]=29;
}
else
i[1]=28;
}
int main(){
HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
int hou,min,sec,day,yea,mon;
hou=23;
min=59;
sec=0;
day=29;
mon=2;
yea=2000;
rn(yea);
while(1){
if(sec==60){
sec=0;
min+=1;
}
if(min==60){
min=0;
hou+=1;
}
if(hou==24){
hou=0;
day+=1;
}
if(day==i[mon-1]+1){
day=1;
mon+=1;
}
if(mon==12){
mon=0;
yea+=1;
}
cout<<setw(4)<<yea<<"年 "<<setw(2)<<mon<<"月"<<" "<<setw(2)<<day<<"号"<<" "<<setw(2)<<hou<<":"<<setw(2)<<min<<":"<<setw(2)<<sec<<endl;
Sleep(1000);
sec+=1;
gotoxy(hout,0,0);
}
return 0;
} |
|