View Code of Problem 81

#include<stdio.h>
#include<math.h>
#include <string.h>
int daytable[2][13] = {
		{0,31,28,31,30,31,30,31,31,30,31,30,31}	, //第0行 表示平年。 这里一定要有个逗号!!! 
		{0,31,29,31,30,31,30,31,31,30,31,30,31}  //第一行 表示闰年 
	};

int IsLeapYear(int year){
	if((year%4==0 && year%100!=0) || (year%400==0)){
		return 1;
	}
	else return 0;
} 

int main(){
	int year, month, day;
	while(scanf("%d %d %d", &year, &month, &day) != EOF) {
		int ans = 0;
		int row = IsLeapYear(year);
		
		for(int i=0; i<month; i++){
			ans += daytable[row][i];
		}
		ans += day;
		printf("%d\n", ans);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 81