1201 18岁生日
来源:互联网 发布:网站授权码系统源码 编辑:程序博客网 时间:2024/05/01 01:06
18岁生日
Problem Description
Gardon的18岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达18岁生日时所经过的天数都是一样的呢?似乎并不全都是这样,所以他想请你帮忙计算一下他和他的几个朋友从出生到达18岁生日所经过的总天数,让他好来比较一下。
Input
一个数T,后面T行每行有一个日期,格式是YYYY-MM-DD。如我的生日是1988-03-07。
Output
T行,每行一个数,表示此人从出生到18岁生日所经过的天数。如果这个人没有18岁生日,就输出-1。
Sample Input
1
1988-03-07
Sample Output
6574
一道考验你细心程度的题,最恶心的wa点就是判断加入你出生和18岁生日那年是不是闰年,如果是闰年,就要判断你你的日子是在3月以前还是以后,如果出生那年是闰年且在3月以前,就要将日子+1,如果你18岁那年是闰年且生日在3月及以后,日子又要+1,最后判断你过的每一年是不是闰年,如果是闰年就+1
附上AC代码:
#include<bits/stdc++.h>using namespace std;using LL =int64_t;int check(int year) { if(year%400==0) return 1; if(year%100==0) return 0; if(year%4==0) return 1; return 0;}int main(){ ios::sync_with_stdio(0); cin.tie(0); int months[15]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int T; cin>>T; while(T--) { int year,month,day; char c; int sum=6570; cin>>year>>c>>month>>c>>day; if(month==2&&!check(year)&&day==29) cout<<-1<<endl; else if(month>12||months[month]<day) cout<<-1<<endl; else { if(check(year)&&month<3) sum++; if(check(year+18)&&month>=3) sum++; for(int i=1;i<18;i++) if(check(year+i)) sum++; cout<<sum<<endl; } } return 0;}
阅读全文
0 0
- 1201 18岁生日
- 1201 18岁生日
- 1201 18岁生日
- HDU 1201 18岁生日
- HDU 1201 18岁生日
- HDU 1201 18岁生日
- hdu - 1201 - 18岁生日
- HDU 1201 18岁生日
- HDU 1201 18岁生日
- 【HDOJ】1201 -> 18岁生日
- hdu-1201-18岁生日
- HDOJ 1201 18岁生日
- HDU: 1201-18岁生日
- hdu 1201 18岁生日
- HDU 1201 18岁生日
- HDU 1201 18岁生日
- hdu-1201-18岁生日
- 18岁生日 hdoj 1201
- ArcGIS水文分析实战教程(3)DEM数据准备
- js之简易计算器
- 创建对话框寻找多个面
- C语言中有关二维数组的指针问题
- 平面设计和UI设计的区别有哪些?
- 1201 18岁生日
- hotplug_uevent机制
- http状态响应码
- Windows Security
- VScode 插件的那些事
- 单链表结点删除
- Spring4.x MVC 整合笔记,使用maven
- 我的博客第一篇
- NYOJ:27-水池数目