来个超级大模拟-----日期计算器
2009-10-07 00:59
218 查看
以前写过的一个东东,思想就是模拟,考虑的情况比较多(闰年等等),程序功能就是给定当前时间和整数m,帮你计算m天后的具体日期,包括周几。输入格式为 2009 10 1 1 1000 ps:当前时间是2009年10月1日周1,计算1000天后的确切日期,仍按输入格式输出。转载注明哪来的哦。。。放码子:
#include<iostream> using namespace std; int num,tmp,y; int month[2][12]={31,29,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31}; class pzj//闰年2月29天 { private: int year1,year2;//闰年366天 public: pzj(int a,int b){year1=a,year2=b;} int getyear(bool); int* getmon(bool); ~pzj(){} }; int pzj::getyear(bool k) { if(!k) return year1; else return year2; } int* pzj::getmon(bool k) { if(!k) return month[0]; else return month[1]; } void display(int i) { if(i==1) printf("按中国的纪年法--YYMMDD--输入当前日期(包括周几):/n"); if(i==2) printf("%d天后的日期是:/n",tmp); if(i==3) printf("请输入您想计算多少天后的确切日期:/n"); if(i==4) printf("继续查询请继续输入,终止程序请键入-1/n"); } bool judge(int k) { if(y%400==0||(y%4==0&&y%100!=0)) return 0; else return 1; } int main() { int ye,mo,da,wee; int i,j,ter; int m,d,week; int *getm;//无用变量 pzj pz(366,365); printf("/t/t%c欢迎使用senjing日期查询器,bug之处敬请指正%c/n",')'-'(',-('('-')')); display(1); scanf("%d%d%d%d",&y,&m,&d,&week); display(3); wee=week; mo=m,da=d,ye=y; while(scanf("%d",&num),num+1) { y=ye,d=da,mo=m;//每次输入重新初始化为原来的值 j=0; i=0; tmp=num; ter=0; week=wee; week+=num%7;//求周几 if(week!=7) week%=7; if(!judge(y))//闰年 { getm=pz.getmon(1);//无用句 while(num>=pz.getyear(judge(y+ter)))//求年份 { num-=pz.getyear(judge(y+ter));//随着年份的增加,要不停判断是否是闰年 ter++; } i=m-1; while(num>month[judge(y+ter)][i])//月份,从初始月份开始累加 { num-=month[judge(y+ter)][i]; i++; } m=i+1; while(m>12) { ter++; m%=12; } num+=d; if(num>month[judge(y+ter)][m-1]) { j++; num-=month[judge(y+ter)][m-1]; } m+=j; while(m>12) { ter++; m%=12; } } else { getm=pz.getmon(judge(y+ter)); while(num>=pz.getyear(judge(y+ter)))//求年份 { num-=pz.getyear(judge(y+ter)); ter++; } i=m-1; while(num>month[judge(y+ter)][i])//月份 { num-=month[judge(y+ter)][i]; i++; } m=i+1; while(m>12) { ter++; m%=12; } num+=d; while(num>month[judge(y+ter)][m-1]) { num-=month[judge(y+ter)][m-1]; j++; } m+=j; while(m>12) { ter++; m%=12; } } display(2); printf("%d-%d-%d,星期%d/n",ter+y,m,num,week); display(4); } system("pause"); return 0; }
相关文章推荐
- UVA12108 Extraordinarily Tired Students(超级大模拟)
- wawawawa超级恶心模拟
- JS模拟超级链接下载文件
- 模拟电视频率可用于超级Wi-Fi
- 安卓Android系统超级终端(终端模拟…
- Hadoop-2.2.0中文文档—— Common - 超级用户模拟别的用户
- 模拟电视频率可用于超级Wi-Fi
- UVa 101 The Blocks Problem (超级模拟)
- Hadoop-2.2.0中文文档—— Common - 超级用户模拟别的用户
- Common - 超级用户模拟别的用户
- Linux模拟超级终端minicom
- Hadoop-2.2.0中文文档—— Common - 超级用户模拟别的用户
- ACMSTEP 1.2.3 QuickSum //超级水题 模拟
- 拥有82944个处理器的超级计算机 40分钟才能模拟一秒人脑活动
- HDU 1278 漂亮面料的设计(超级模拟)
- XGen XGsab苹果IOS神器一键新机改串清理超级全息备份支持IOS7-8-9-10全系模拟超IGV8
- 【Sharepoint代码段】MOSS模拟超级管理员的方法
- js javascript 模拟点击 超级链接点击 转
- Codeforces Beta Round #3 / 3C Tic-tac-toe (超级模拟)
- Linux模拟超级终端minicom(二)