Date类问题1
来源:互联网 发布:横县教研室网络硬盘 编辑:程序博客网 时间:2024/05/18 00:46
题目描述:
思路分析:固定原点,两个日期与原点之间的距离之差即为这两个日期之间的时间
差。
代码:
#include<stdio.h>#define isyear(x) x%100!=0&&x%4==0||x%400==0?1:0//宏定义判断是否是闰年,闰年2月29天,平年28天int dayofMonth[13][2]={//预存每个月的天数0,0,31,31,28,29,31,31,30,30,31,31,30,30,31,31,31,31,30,30,31,31,30,30,31,31};struct Date{int day;int month;int year;void nextDay(){day++;if(day>dayofMonth[month][isyear(year)]){ day=1; month++; if(month>12){ month=1; year++;}}}};int buf[5001][13][32];//定义为全局变量,因为占用内存过大int abs(int x){return x<0?-x:x;}int main(){Date tmp;int count=0;tmp.year=0;tmp.month=1;tmp.day=1;while(tmp.year!=5001){ buf[tmp.year][tmp.month][tmp.day]=count; tmp.nextDay(); count++;}int y1,m1,d1;int y2,m2,d2;while(scanf("%4d%2d%2d",&y1,&m1,&d1)!=EOF){ scanf("%4d%2d%2d",&y2,&m2,&d2); printf("%d\n",abs(buf[y1][m1][d1]-buf[y2][m2][d2])+1);}return 0;}
阅读全文
0 0
- Date类问题1
- Date类问题2
- Date问题
- javascript的Date问题
- 遇到date问题
- 关于Date奇怪问题
- Date Calender的问题
- Oracle date问题
- date类型数据格式问题
- gson转换问题Date
- Date转化问题
- load date infile问题
- 【date】java Date getYear()获取年份问题
- Date类
- Date类
- Date类
- Date类
- Date类
- 16
- mysql破解密码并修改密码
- Fragment 使用add 和 hide 生命周期
- 17
- jquery广告弹出
- Date类问题1
- 移动端,控制头部尾部固定
- 18
- DCI in C++ 语法糖
- 查看linux中某个端口(port)是否被占用
- 19
- Protecting the Flowers
- 20
- 【Hadoop--04】Hadoop读文件