文章

49

粉丝

49

获赞

8

访问

11.5k

头像
C++
P1542 云南大学机试题
发布于2024年3月17日 19:18
阅读数 136

#include<iostream>
#include<string>
using namespace std;

const int p[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

struct date
{
	int year;
	int month;
	int day;
};

bool is_goodyear(int n)
{
	if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
	{
		return true;
	}
	return false;
}

int main()
{
	string s;
	int pos1, pos2;
	cin >> s;
	int y, m, d;
	pos1 = s.find('-');
	pos2 = s.find_last_of('-');
	y = stoi(s.substr(0, pos1));
	m = stoi(s.substr(pos1 + 1, pos2 - pos1 - 1));
	d = stoi(s.substr(pos2 + 1));
	date a;
	a.year = y;
	a.month = m;
	a.day = d;
	int r = 0;
	while (a.month != 0)
	{
		a.month--;
		r += p[a.month];
		if (is_goodyear(a.year) && a.month == 2)
			r++;
	}
	r += a.day;
	cout << r << endl;
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发