输入:年
月
日
输出:天数
例如:输入:2012
12
31
输出:366
闰年、平年分开处理。不多说,直接上代码:
#include<iostream>
#include<string>
using namespace std;
int leap[12]={0,31,29,31,30,31,30,31,31,30,31,30};
int nonleap[12]={0,31,28,31,30,31,30,31,31,30,31,30};
int getOutDay(int,int,int);
int main()
{
int a,b,c;
cin>>a>>b>>c;
getOutDay(a,b,c);
//system("pause");
return 0;
}
int getOutDay(int y,int m,int d)
{
int number=0;
if(y<=0||m<=0||d<=0)
return -1;
if(y%100==0&&y%400==0||y%100!=0&&y%4==0)
{
for(int i=1;i<m;i++)
number+=leap[i];
}
else
{
for(int i=1;i<m;i++)
number+=nonleap[i];
}
number+=d;
cout<<number<<endl;
return 0;
}