HDU 1201 18岁生日
2015-07-23 20:29
435 查看
18岁生日
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23160 Accepted Submission(s): 7404
[align=left]Problem Description[/align]
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
[align=left]Input[/align]
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。
[align=left]Output[/align]
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。
[align=left]Sample Input[/align]
1
1988-03-07
[align=left]Sample Output[/align]
6574
[align=left]Author[/align]
Gardon
[align=left]Source[/align]
Gardon-DYGG Contest 2
[align=left]Recommend[/align]
JGShining | We have carefully selected several similar problems for you: 1205 1106 1215 1228 1234
这题就是需要注意一些细节,一个是开始的第一年是不是闰年,是闰年的话在2.29前面还是后面,一个是18岁那年是不是闰年,是的话在2.29前面还是后面,还有就是一个闰年的2.29的特判就没了。杭电讨论组里一个人的数据非常好,在代码最后的注释里。
#include<math.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define N 155 int y,m,d,day_cnt,f1; int judge(int year) { if( (year%4==0)&&(year%100!=0) || year%400==0 )return 1; else return 0; } int main() { int t;cin>>t; while(t--) { day_cnt=f1=0; scanf("%d-%d-%d",&y,&m,&d); if(judge(y)&&m==2&&d==29) { cout<<-1<<endl; continue; } if(judge(y)&&m>=3){f1=-1;} if(judge(y+18)&&m<3){f1=0;} if(judge(y+18)&&m>=3){f1=1;} for(int i=0;i<18;i++) { int yy=y+i; if(judge(yy))day_cnt+=366; else day_cnt+=365; } cout<<day_cnt+f1<<endl; } return 0; } /* 13 2004-1-22 2004-2-28 2004-2-29 2004-4-20 2003-2-20 2003-2-28 2003-3-20 2002-2-20 2002-2-28 2002-3-20 2001-2-20 2001-2-28 2001-3-20 */
相关文章推荐
- 入行时的面试题(大家不要笑哦)
- Snail—UI学习之UITextField
- curl学习(实例不断总结)
- nyoj844 A+B Problem(V)
- 软件工程师面试题
- Struts2_1_struts2建立一个执行环境
- 13.Roman to Integer (HashTable)
- 编写可变参数c函数
- keil c51的内部RAM(idata)动态内存管理程序
- Codeforces Round #313 (Div. 2)D
- 二分 hdu2141 Can you find it?
- Python Split函数的用法总结
- 【POJ】【2019】
- 动态规划 钢条切割问题 两种方法 自底而上 自上而下的方法
- Android测试提升效率批处理脚本(二)
- C - 链表,推荐
- 【Struts2框架】第二节Result-向结果传参数
- iOS前期OC训练OC_06字典
- shell学习
- 数据库分组函数