跳到正文

题解

[GESP202303 一级] 每月天数题解

代严2014约 1 分钟
原文

这是 2026年1月10日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年12月7日
收录
2026年1月10日
更新
2026年11月17日
篇幅
约 1 分钟
题目
B3835

版本

  1. v2当前
  2. v1

这题非常简单,我就不废话了,自己看注释。 语言(C++):

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int year,month;
	cin>>year>>month;
	if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){//先判断月是否为大月
		cout<<31;//就输出31
	}else{
		if(month==4||month==6||month==9||month==11){//如果是小月
			cout<<30;//输出30
  }else{//如果都不是if((month==2&&year%4==0&&year%100!=0)||year%400==0){//(month==2&&year%4==0&&year%100!=0)这里要加括号,不然会错一个点
				cout<<29;//输出29;
			}else{
				cout<<28;否则输出28
			}
		}
	}
	
	return 0;
}