这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1201
这题的关键就是看月份是否大于3. 分两种情况讨论: 若大于3,则判断是否是闰年按后一年看。 若小于等于3,则判断是否是闰年按本年看。
这里给大家一些测试数据: 测试数据:
1980-02-29 -1 1988-03-03 6574 1987-03-03 6575 1970-03-03 6575 1988-02-02 6575 1987-02-02 6575 1970-02-02 6574 1988-02-28 6575 1970-02-28 6574 1987-02-28 6575
// Author: Tanky Woo
// HDOJ 1201
// Accepted 1201 0MS 264K 741 B C++ Tanky Woo
#include
#include
using namespace std;
int nCases;
bool Is_leap(int n)
{
if((n%4==0 && n%100!=0) || n%400==0)
return 1;
else
return 0;
}
int main()
{
scanf("%d", &nCases;);
int year, month, day;
while(nCases--)
{
char tmp;
// 先开始我还傻傻的去用string表示...麻烦...
cin >> year >> tmp >> month >> tmp >> day;
if(month==2 && day==29)
{
cout << -1 << endl;
continue;
}
int run=0;
if(month>=3)
{
for(int i=1; i<=18; ++i)
if(Is_leap(year+i))
run++;
}
else
{
for(int i=0; i<18; ++i)
if(Is_leap(year+i))
run++;
}
cout << 365*18+run << endl;
}
return 0;
}