链接:click here
题意:
1
1988-03-07
7305
思路:
<1>将出生年所经历的天数与20岁生日那年度过的天数合在一起算作一年。
<2>不考虑闰年,则20年共度过20*365天。
<3>单独考虑,若出生年是闰年,并且在2月29日之前出生的,必定经过2月29日这天,总天数加1,对于20岁那年,若该年是闰年,并且在2月28日之后出生的同样必定经过2月29这天,所以总天数加1.
<4>其他年份只要是闰年,则总天数加1天即可。
<5>特殊情况
代码:
#include <math.h>
#include <queue>
#include <deque>
#include <vector>
#include <stack>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) a>b?a:b
#define Min(a,b) a>b?b:a
#define mem(a,b) memset(a,b,sizeof(a))
int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
const double eps = 1e-6;
const double Pi = acos(-1.0);
static const int inf= ~0U>>2;
static const int maxn =110;
int h[100],w[100],Map[200];
int isleap(int yy)
{
if((yy%4==0&&yy%100!=0)||yy%400==0) return 1;
return 0;
}
int main()
{
int n,m,i,j;
cin>>n;
while(n--)
{
int yy,mm,dd;
int data=20*365;
scanf("%d-%d-%d",&yy,&mm,&dd);
if(!isleap(yy+20)&&mm==2&&dd==29)
{
puts("-1");
continue;
}
if(isleap(yy)&&(mm<2||(mm==2&&dd<=28))) data++;
if(isleap(yy+20)&&(mm>2||(mm==2&&dd==29))) data++;
for(int i=yy+1; i<=yy+19; i++)
{
if(isleap(i)) data++;
}
printf("%d\n",data);
}
return 0;
}
NYOJ 312 && HDU 1201 过生日(日期计算)
原文地址:http://blog.csdn.net/u013050857/article/details/43939743