计算天数
程序员文章站
2022-06-07 15:14:13
...
判断是平年或闰年的方法:if(year%100!=0 && year%4==0 || year%400==0)
代码如下:
//可以将每个月的天数保存在数组中
#include<iostream>
using namespace std;
int main()
{
int year_y[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int year_n[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int m;
cin>>m;
while(m--)
{
int year,month,day;
cin>>year>>month>>day;
int *Year;//
if(year%100!=0&&year%4==0 || year%400==0)
Year=year_y;
else Year=year_n;
int i,num=0;
for(i=0;i<month-1;i++)
num+=Year[i];
num+=day;
cout<<num<<"\n";
}
return 0;
}