杭电acm----1201 18岁生日
来源:互联网 发布:淘宝怎么做直通车引流 编辑:程序博客网 时间:2024/05/17 01:32
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1201
解题思路:
首先判断有没有18岁生日:
*****当你输入的月份是2,日期为29,代表你出生的就是闰年,你只要判断18年后是不是闰年就好了,若不是闰年,代表没有18岁生日,反之,则有。
若有18岁生日,算从出生到18岁生日所占的天数。
*****从出生那年1月1日开始算,到18岁那年的1月1日所占的天数,再加上你18岁那年从1月1日到你生日的天数,再减去你出生那年从1月1日到你出生所占的天数
#include <iostream> using namespace std; int type(int y) { if (y%4 != 0 || (y%100==0&&y%400 !=0)) return 0; else return 1; } int main() { int n,y,m,d,i,years,month,j,s,k,x; int days[2][13] = {0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31,31,30,31,30,31}; int year[2]={365,366}; cin>>n; while(n--) { x=years=month=0; scanf("%d-%d-%d",&y,&m,&d); k=y+18; if(type(k)==0&&m==2&&d==29) { cout<<"-1"<<endl; } else { for(i=y;i<k;i++) { years+=year[type(i)]; } for(j=1;j<m;j++) { if(type(y)==0) x+=days[0][j]; else x+=days[1][j]; if(type(k)==0) month+=days[0][j]; else month+=days[1][j]; } s=years+month-x; cout<<s<<endl; } } return 0; }
0 0
- 杭电ACM 1201 18岁生日
- 杭电acm----1201 18岁生日
- 杭电ACM 1201 18岁生日
- 杭电ACM--HDU1201--18岁生日
- 18岁生日(杭电1201)
- 杭电1201 18岁生日
- 杭电 HDU 1201 18岁生日
- 杭电1201 18岁生日
- 杭电 1201 18岁生日
- 杭电1201 18岁生日
- 杭电1201 18岁生日
- 【杭电】[1201]18岁生日
- 杭电1201之18岁生日
- 【杭电-oj】-1201-18岁生日
- 杭电 1201 18岁生日
- 【杭电1201】18岁生日
- 【杭电1201】18岁生日
- 杭电 1201 18岁生日
- [38] Count and Say
- Graphics平移缩放旋转
- centos6.5安装python2.7.9
- 教你怎么引入百度地图
- 微信互联网推广经验7+1
- 杭电acm----1201 18岁生日
- 三魂七魄,看看哪个已不在您身上?
- AlertDialog 宽度全屏
- svn is already locked解决方案
- Moving a drawn line with the mouse
- 想做自动化测试需要深入的几点建议
- mysql分表分区方案实测:MyISAM引擎分表 or mysql表分区
- 快速排序
- C# Graphic - DrawLine - draw line and move it