70分求助!!help
查看原帖
70分求助!!help
819682
Exile_Code楼主2023/7/21 21:19
#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;
}
2023/7/21 21:19
加载中...