Exile_Code @ 2023-07-21 21:19:39
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>
typedef long long ll;
#define first x
#define second y
int main() {
int y, m, d, yy, mm, dd;
scanf("%4d%2d%2d", &y, &m, &d);
scanf("%4d%2d%2d", &yy, &mm, &dd);
int mouth[13] = { 0,31,28,31,30,31
,30,31,31,30,31,30,31 };
long long res = 0;
for (int i = y; i <= yy; i++) {
mouth[2] = 28;
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
mouth[2] = 29;
string a = to_string(i);
reverse(a.begin(), a.end());//年份反转
int a_m = ((a[0] - '0') * 10 + a[1] - '0');
int a_n = ((a[2] - '0') * 10 + a[3] - '0');//获取月日
if (y==yy){//开始和结尾相等的时候
if ( a_m >= m && a_n >= d
&&a_m<=mm&&a_m<=dd
&&a_m<= 12 && a_m >= 1
&&a_n <= mouth[a_m] && a_n > 0)
res++;
}
else if (i == y) {//开始的时候
if (a_m >= m && a_n >= d
&& a_m <= 12 && a_m >= 1
&& a_n <= mouth[a_m] && a_n > 0)
res++;
}
else if (i == yy) {//结尾的时候
if (a_m <= mm && a_m <= dd
&& a_m <= 12 && a_m >= 1
&& a_n <= mouth[a_m]&&a_n>0)
res++;
}
else//其余情况
if (a_m<=12&&a_m>=1
&&a_n <= mouth[a_m] && a_n > 0)
res++;
}
cout << res ;
return 0;
}
by Lizj @ 2023-07-22 08:00:28
@Exile_Code 建议看看这个
by Exile_Code @ 2023-07-22 13:54:14
@Mr__AC 可以举一个例子吗?我想的是,如果y==yy,那只会判断一次,循环终止了啊,其余的情况下,else if不是只会选择一个进行执行啊,那里造成了重复啊?我下载了第一个wrong的用例,但是明明跑出来的结果跟答案一样啊,可以举一个例子嘛,大佬可以举一个例子嘛