第几天

在我们现在使用的日历中, 闰年被定义为能被4整除的年份,但是能被100整除而不能被400整除的年是例外,它们不是闰年。例如:1700, 1800, 1900 和 2100不是闰年,而 1600, 2000 和 2400是闰年。

给定公元2000年1月1日后的某年某月某日(包括2000年1月1日),你的任务:(1)给出这一天从公元2000年1月1日开始逝去的天数,(2)判断这一天是当年的第几天。


#include<iostream>
using namespace std;
int yearDays(int year)                                                
{
     if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 366;
else
return 365;
}
int monthDays(int year, int month)                                        
{
    int a[13];
int k=0;
int i;
    for(i=1;i<13;i++)
{
if(i==4||i==6||i==9||i==11)
a[i]=30;
else
a[i]=31;
}
if(yearDays(year)==366)
a[2]=29;
else
a[2]=28;
for(i=1;i<month;i++)
k+=a[i];
return k;
}
int cal(int year, int month, int day)            
{
int c,temp=0,m,i;
for(i=2000;i<year;i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
++temp;
}
m=(year-2000-temp)*365+temp*366;
c=m+monthDays(year,month)+day-1;
return c;
}
int co(int year,int month,int day)
{
int c;
c=monthDays(year,month)+day;
return c;
}
int main()
{
    int year,month,day;
while(cin>>year>>month>>day)
{
cout<<cal(year,month,day)<<endl;
cout<<co(year,month,day)<<endl;
}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值