洛谷 P5690 [CSP-SJX2019]日期

洛谷 P5690 [CSP-SJX2019]日期

思路

大水题一道,判断一下即可

输入直接用快读读两个数就行了,不需要读一个(char)类型的字符

年月不能为(0),月份不能超过(12),天数不能超过(31)

另外在二月天数的时候不能超过(28),在(4、6、9、11)月天数不能超过30

这样就好啦

代码

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

inline int read() {
	char c = getchar(); int x = 0, f = 1;
	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1; 
	for( ; isdigit(c); c = getchar()) x = x * 10 + c - 48;
	return x * f;
}

int n, m, ans = 0;

int main() {
	n = read(), m = read();
	if(n > 12 || n == 0) ans++;
	if(m > 31 || ((n == 4 || n == 6 || n == 9 || n == 11)&&(m > 30)) || m == 0 || (n == 2 && m > 28)) ans++;
	cout << ans << '
';
	return 0;
}
原文地址:https://www.cnblogs.com/loceaner/p/12007945.html