您的位置:首页 > 编程语言

2015 编程之美 资格赛 第一题 hihocoder 区间闰年 2月29 数量 模拟题

2015-04-17 15:46 239 查看
#include <string.h>   ->memset()的头文件

http://hihocoder.com/contest/msbop2015qual/problem/1

#include <iostream>
#include <string>
#include <stdio.h>
#include <memory>
#include <string.h>
using namespace std;
string m[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"};
class year2
{
public :
int year;
string mouth;
int day;
int i_mouth;
int special;
void tran_mouth()
{
for(int i=0;i<12;i++)
if(mouth==m[i])
i_mouth=i+1;
};
void cal()
{
special=year/4-year/100+year/400;
};
bool is_special()
{
if(year%400==0||(year%4==0&&year%100!=0))
{
return true;
}
return false;
};
bool before_include_special()
{
if(i_mouth<2||(i_mouth==2&&day<=29))
return true;
else
return false;
};
bool before_special()
{
if(i_mouth<2||(i_mouth==2&&day<29))
return true;
else
return false;
};
};
int main()
{
int T;
int Case=0;
cin>>T;

while(T--)
{
char t;
Case++;
year2 start;
year2 end;
cin>>start.mouth;
cin>>start.day;
cin>>t;
cin>>start.year;

cin>>end.mouth;
cin>> end.day;
cin>> t;
cin>> end.year;

start.tran_mouth();
start.cal();
end.tran_mouth();
end.cal();

int ans= end.special- start.special;
if(start.is_special()&&start.before_include_special())
{
ans+=1;
}
if(end.is_special()&&end.before_special())
{
ans-=1;
}
cout<<"Case #"<<Case<<": "<<ans<<endl;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: