卡50分,不知道哪里出错了。。。
查看原帖
卡50分,不知道哪里出错了。。。
741052
CSFei楼主2023/9/29 17:14

这是代码

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;


int main()
{
	string begin, end;
	getline(cin, begin);
	getline(cin, end);

	int bYear, bMonth, bDay;//把起始和末尾全部记录,方便枚举
	int eYear, eMonth, eDay;

	bYear = stoi(begin.substr(0, 4));//分割文本
	bMonth = stoi(begin.substr(4, 2));
	bDay = stoi(begin.substr(5, 2));

	eYear = stoi(end.substr(0, 4));//分割文本
	eMonth = stoi(end.substr(4, 2));
	eDay = stoi(end.substr(5, 2));

	int HW = 0;

	for (size_t i = 0; i < (eYear - bYear + 1); i++)
	{
		int Year = bYear + i;
		string str = to_string(Year);
		string temp = str;
		for (size_t o = 0; o < 4; o++)
		{
			temp[o] = str[3 - o];
		}
		str += temp;


		int Month = stoi(str.substr(4, 2));
		int Day = stoi(str.substr(5, 2));
		if (Month > 12)
			continue;
		if (Month == 0)
			continue;
		if (Day > 31)
			continue;
		temp = ",1,3,5,7,8,10,12,";
		if (temp.find("," + to_string(Month) + ",") == string::npos)
		{
			if (Day == 31)
				continue;
		}

		if (Month == 2)
		{
			if (str == "92200229")
				HW++;
			else
				continue;
		}

		if (Year == eYear)
		{
			if (Month > eMonth)
				continue;
			if (Month == eMonth)
				if (Day >= eDay)
				continue;
		}
		
		if (Year == bYear)
		{
			if (Month < bMonth)
				continue;
			if (Month == bMonth)
				if (Day <= bDay)
					continue;
		}
		HW++;
	}
	printf("%d", HW);

}
2023/9/29 17:14
加载中...