李强


私信TA

用户名:uq_15621203389

访问量:1571

签 名:

等  级
排  名 613
经  验 4052
参赛次数 0
文章发表 25
年  龄 0
在职情况 教师
学  校
专  业

  自我简介:

解题思路:

题目主要要搞清楚什么是闰年,什么是平年,然后闰年每个月有多少天,平年每个月有多少天。



注意事项:

参考代码:

#include <bits/stdc++.h>
using namespace std;

struct date{
	int year;
	int month;
	int day;
};
int main()
{
	struct date today;
	cin>>today.year;
	cin>>today.month;
	cin>>today.day;
	//判断是不是闰年 ,一般的年份除以4,有余数的是平年,没有余数的是闰年,
	//但如果是年份是整百的,那么该年份除以400,有余数的是平年,没有余数的是闰年。 
	bool tag;
	if(today.year%100!=0 && today.year%4==0||today.year%400==0)
	{
		tag=1;
		}	else tag=0;
	//闰年1~12月分别为31天、29天、31天、30天、31天、30天、31天、31天、30天、31天、30天、31天 
	//平年1~12月分别为 31天、28天、31天、30天、31天、30天、31天、31天、30天、31天、30天、31天 
	int run[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	int ping[12]={31,28,31,30,31,30,31,31,30,31,30,31}; 
	//如果是闰年,
	int sum=0; 
	if(tag==1){
		for(int i=0;i<today.month-1;i++)
		{
			sum+=run[i];
		}
		sum+=today.day; 
	} 
	//如果是平年 
	else 
	{
		for(int i=0;i<today.month-1;i++)
		{
			sum+=ping[i];
		}
		sum+=today.day; 
	}
	cout<<sum<<endl;
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区