文章

79

粉丝

221

获赞

45

访问

164.0k

头像
日期累加
P1446 北京理工大学机试题
发布于2023年3月27日 20:18
阅读数 1.9k

#include <iostream>
using namespace std;
typedef struct dat {
	int y, m, d;
}dat;
bool IsR(int year) {
	return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
const int mon1[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
const int mon2[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
int main() {
	int m;
	cin >> m;
	dat temp;
	for (int i = 0; i < m; i++) {
		int p;
		scanf("%d %d %d %d", &temp.y, &temp.m, &temp.d, &p);
		for (temp.y; p - (IsR(temp.y) ? 366 : 365) > 0; temp.y++)
			p -= IsR(temp.y) ? 366 : 365;
		if (p - (IsR(temp.y) ? mon1[temp.m - 1] : mon2[temp.m - 1]) + temp.d > 0) {
			p = p - (IsR(temp.y) ? mon1[temp.m - 1] : mon2[temp.m - 1]) + temp.d;
			temp.m++;
			if (temp.m == 13)
				temp.y++, temp.m = 1;
			temp.d = 0;
			while (p - (IsR(temp.y) ? mon1[temp.m - 1] : mon2[temp.m - 1]) > 0) {
				p -= (IsR(temp.y) ? mon1[temp.m - 1] : mon2[temp.m - 1]);
				temp.m++;
				if (temp.m == 13)...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发