Discuz! Board

 找回密码
 立即注册
查看: 704|回复: 0

9.29 时钟

[复制链接]

54

主题

66

帖子

574

积分

高级会员

Rank: 4

积分
574
发表于 2022-9-29 19:33:20 | 显示全部楼层 |阅读模式
#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;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 11:15 , Processed in 0.047124 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.. 技术支持 by 巅峰设计

快速回复 返回顶部 返回列表