Discuz! Board

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

2022.10.14

[复制链接]

15

主题

19

帖子

4118

积分

论坛元老

Rank: 8Rank: 8

积分
4118

墨海马 Lv:15
发表于 2022-10-14 18:17:52 | 显示全部楼层 |阅读模式
#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);
}
struct time
{
        int n;
        int y;
        int r;
        int s;
        int f;
        int m;
}a;

int pinrun()
{        
    if(a.n%4==0&&a.n%100!=0||a.n%400==0)
    {
                return 1;
    }
    return 0;
}
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);
        a.n=2001;
        a.y=2;
        a.r=28;
        a.s=23;
        a.f=59;
        a.m=55;

        int b[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)
        {
                a.m++;
                Sleep(1000);
                if(a.m==60)
                {
                        a.f++;
                        a.m=0;
                }
                if(a.f==60)
                {
                        a.s++;
                        a.f=0;
                }
                if(a.s==24)
                {
                        a.s=0;
                        a.r++;
                }
                if(a.r==b[pinrun()][a.y-1]+1)
                {
                        a.y++;
                        a.r=1;
                }
                if(a.y==12)
                {
                        a.n++;
                        a.y=1;
                }

                cout<<setw(2)<<a.n<<"年"<<setw(2)<<a.y<<"月"<<setw(2)<<a.r<<"日"<<setw(2)<<a.s<<':'<<setw(2)<<a.f<<':'<<setw(2)<<a.m;
                CaculateWeekDay(a.n,a.y,a.r);
                                gotoxy(hout,0,0);
                        }
        return 0;
}

回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-5-30 12:08 , Processed in 0.058010 second(s), 26 queries .

Powered by Discuz! X3.4

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

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