Discuz! Board

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

时钟第三版

[复制链接]

49

主题

70

帖子

23万

积分

论坛元老

Rank: 8Rank: 8

积分
232976

大王燕 Lv:51
发表于 2022-10-13 19:08:59 | 显示全部楼层 |阅读模式
  1. #include<bits/stdc++.h>
  2. #include <windows.h>
  3. using namespace std;
  4. int a;
  5. int hour,minute,second,year,month,day,week;
  6. int month1[2][12]={32,29,32,31,32,31,32,32,31,32,31,32,
  7.                                    32,30,32,31,32,31,32,32.31,32,31,32};
  8. void gotoxy(HANDLE hout, int x, int y);
  9. void gotoxy(HANDLE hout, int x, int y){
  10.   COORD pos;
  11.   pos.X = x;
  12.   pos.Y = y;
  13.   SetConsoleCursorPosition(hout, pos);
  14. };
  15. int pingrun()
  16. {
  17.         if(year%4==0)
  18.     {
  19.         if(year%100==0)
  20.         {
  21.             if(year%400==0)
  22.                 a=1;
  23.             else
  24.                 a=0;
  25.         }
  26.         else
  27.             a=1;
  28.     }
  29.     else
  30.         a=0;
  31.         return a;
  32. }
  33. void CaculateWeekDay(int y,int m, int d)
  34. {
  35.         if(m==1||m==2) {
  36.         m+=12;
  37.         y--;
  38.         }
  39.         int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
  40.         switch(iWeek)
  41.         {
  42.         case 0: printf("星期一\n"); break;
  43.         case 1: printf("星期二\n"); break;
  44.         case 2: printf("星期三\n"); break;
  45.         case 3: printf("星期四\n"); break;
  46.         case 4: printf("星期五\n"); break;
  47.         case 5: printf("星期六\n"); break;
  48.         case 6: printf("星期日\n"); break;
  49.         }
  50. }
  51. int main()
  52. {
  53.         HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
  54.     cin>>year;
  55.     cout<<"年";
  56.     cin>>month;
  57.     cout<<"月";
  58.     cin>>day;
  59.     cout<<"日"<<endl;
  60.         //cout<<"星期";
  61.        
  62.     cin>>week;
  63.     cin>>hour;
  64.     cout<<":";
  65.     cin>>minute;
  66.     cout<<":";
  67.     cin>>second;
  68.    
  69.     CaculateWeekDay(year,month,day);
  70.     for(;;second++)
  71.     {
  72.         if(second==60)
  73.         {
  74.             minute+=1;
  75.             second=0;
  76.             if(minute==60)
  77.             {
  78.                 hour+=1;
  79.                 minute=0;
  80.                 if(hour==24)
  81.                 {
  82.                     hour=0;
  83.                     second=0;
  84.                     minute=0;
  85.                     day+=1;
  86.                         hour=0;
  87.                                         if(day==month1[pingrun()][month-1])
  88.                                         {
  89.                                                 month+=1;
  90.                                                 day=1;
  91.                                                 if(month==13)
  92.                                                 {
  93.                                                         year+=1;
  94.                                                         month=1;
  95.                                                 }
  96.                                         }        
  97.                                 }
  98.                         }
  99.                 }                       
  100.         else
  101.         {
  102.             cout<<setw(4)<<year<<"年"<<setw(2)<<month<<"月"<<setw(2)<<day<<"日"<<'\n';
  103.             cout<<setw(2)<<hour<<":"<<setw(2)<<minute<<":"<<setw(2)<<second<<'\n';
  104.                         Sleep(100);
  105.             gotoxy(hout,0,12);
  106.         }      
  107.     }
  108.         
  109.     return 0;
  110. }
复制代码


回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2025-2-13 05:30 , Processed in 0.050537 second(s), 28 queries .

Powered by Discuz! X3.4

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

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