CCF日期计算,解题思路,C++,Java

解题思路:

首先判断是闰年还是平年,若是瑞年则28+1,平年28+0

bool flag = n%4 ==0&& n%100 != 0 || n%400 == 0 ;
	if(flag){
		t=1;
	}else{
		t=0;
	}


#include <iostream>
using namespace std;
int main(){
	int n,d,t;

	cin>>n>>d;
	if(d <=31){
		cout<<1<<endl;
		cout<<d;
		return 0;
	}
	bool flag = n%4 ==0&& n%100 != 0 || n%400 == 0 ;
	if(flag){
		t=1;
	}else{
		t=0;
	}
	if( d <=59+t){// 31+28 + t 如果t=1 则 d< 60 即2月有29天,若是0,则2月有28天 
		cout<<2<<endl;
		cout<< d-31;
	}else if( d <= 90+t){ // 31 + 2月(28 + t)+ 31 = 90+t  如果t=1 则 d< 60 即2月有29天,若是0,则2月有28天 ,下面的情况类似 
		cout<<3 <<endl;
		cout<< d-(59+t);
	}else if( d <= 120+t){
		cout<<4<<endl;
		cout<< d-(90+t);
	}else if( d <= 151+t){
		cout<<5 <<endl;
		cout<< d-120-t;
	}else if( d <= 181+t){
		cout<<6 <<endl;
		cout<< d-151-t;
	}else if( d <= 212+t){
		cout<<7<<endl;
		cout<< d-181-t;	
	}else if( d <= 243+t){
		cout<<8 <<endl;
		cout<< d-212-t;
	}else if( d <= 273+t){
		cout<<9 <<endl;
		cout<< d-243-t;
	}else if( d <= 304+t){
		cout<<10 <<endl;
		cout<< d-273-t;
	}else if( d <= 334+t){
		cout<<11 <<endl;
		cout<< d-304-t;
	}else if( d <= 365+t){
		cout<<12 <<endl;
		cout<< d-334-t;		
	}
	return 0;
} 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值