zzulioj 1129: The first few days

1129: The first few days

Title Description

You know, 2012-1-1 was the year the first days, but 9999-9-9 it? Give you a specific date, the calculation date is the first day of the year.

Entry

Enter a date in the format: Year-month-day. year is a positive integer less than 9999.

Export

An integer that indicates the date is the first day of the year.

Sample input Copy

2012-3-1

Sample output Copy

61

C

#include<stdio.h>
int main()
{
	int y,m,d,i,s=0;
	scanf("%d-%d-%d",&y,&m,&d);
	for(i=1;i<m;i++){
		if(i==4 || i==6 || i==9 || i==11)
			s+=30;
		else if(i==2)
			s+=28;
		else
			s+=31;
	}
	if(i>2 && y%4==0 && y%100!=0 || y%400==0)
		s+=1;
	printf("%d\n",s+d);
	return 0;
}
Published 10 original articles · won praise 0 · Views 177

Guess you like

Origin blog.csdn.net/qq_45845830/article/details/104098107