計算第幾天

 avatar
user_3763047219
c_cpp
2 years ago
655 B
5
Indexable
Never
#include <stdio.h>
#include<stdbool.h>

int main()
{
	bool year = false;
	int y,m,d;
	int month[12]{ 31,0,31,30,31,30,31,31,30,31,30,31 };
	int day = 0;
	scanf("%d%d%d", &y, &m, &d);

	if (y % 4 == 0 && y % 100 != 0) {
		year = true;
	}
	if (y % 400 == 0) {
		year = true;
	}

	if (m > 2) {
		if (year == 1) {
			for (int i = 0;i < m-1;i++) {
				day = day + month[i] ;
			}
			day = day + 29;
		}
		else {
			for (int i = 0;i < m-1 ;i++) {
				day = day + month[i] ;
			}
			day = day + 28;
		}
	}
	else {
		for (int i = 0;i < m - 1;i++) {
			day = day + month[i] ;
		}
	}

	day = day + d;
	printf("%d", day);
	
}