HDU2005 第几天?
2016-06-25 14:38
204 查看
问题链接:HDU2005 第几天?。功能是对给定的日期,算出是那一年的第几天。
这是个入门训练题,自然用C语言编写程序。
这里给出的程序,与一般教科书的做法略有不同,程序逻辑要简洁一些。
AC程序如下:
这是个入门训练题,自然用C语言编写程序。
这里给出的程序,与一般教科书的做法略有不同,程序逻辑要简洁一些。
AC程序如下:
/* HDU2005 第几天? */ #include <stdio.h> int leapyear_day(int year, int month) { // 1月或2月不用加1天,其他月份润年加1天,非润年不用加1天 if(month <= 2) return 0; else return ( ((year%4==0) && (year%100!=0)) || (year%400==0) )?1:0; } int main(void) { int year, month, day; int days; int monthsum[] = { // 到某月份的天数,润年另外加天数 0 // 1月 , 31 // 2月 , 31+28 // 3月 , 31+28+31 // 4月 , 31+28+31+30 // 5月 , 31+28+31+30+31 // 6月 , 31+28+31+30+31+30 // 7月 , 31+28+31+30+31+30+31 // 8月 , 31+28+31+30+31+30+31+31 // 9月 , 31+28+31+30+31+30+31+31+30 // 10月 , 31+28+31+30+31+30+31+31+30+31 // 11月 , 31+28+31+30+31+30+31+31+30+31+30 // 12月 }; while(scanf("%d/%d/%d", &year, &month, &day) != EOF) { // 天数 = 润年需要加的天数(根据年和月计算) + 到某月天数 + 月内天数 days = leapyear_day(year, month) + monthsum[month-1] + day; // 输出结果 printf("%d\n", days); } return 0; }
相关文章推荐
- pthread_create
- leetcode 165 Compare Version Numbers
- JAVA初识
- 把A表的某字段值赋B表中的某字段
- 如何编写高质量的易语言代码?
- ADDM (Automatic Database Diagnostic Monitor)
- 现阶段正在读的书单
- 四则运算分析计算(非常值得学习嗷)
- 快速搜索工具Everything
- 基于交通路标分类的多列深度神经网络(MCDNN)
- 基于日志的实时分析方法及系统
- 好开森,不过审核好慢嗷,都提交一星期了。。
- Css转Sass、Css转Less在线工具
- 在线打字练习
- 给无边框窗口增加阴影
- iphone6 电影支持什么格式
- [WebKit内核]EasyCKL开源浏览器库 6.1 支持调试运行了
- Android camera 竖直拍照 获取竖直方向照片
- 自定义Theme(1)
- XtraBackup2.3.3安装配置使用(innobakupex)