Enter a date from the keyboard in the format of ymd.
It is required to calculate the number of days between this date and October 1, 1949.
E.g:
User input: 1949-10-2
Program output: 1
User input: 1949-11-1
program output: 31
Input format
Enter the year, month, and date. Every two numbers are separated by a-to ensure that the data is legal.
Output format
A number indicates how many days are this date from the founding day of New China.
#include<stdio.h>
int main()
{
int y,m,d,day,d1=0,d2=0,d3=0,x;
scanf("%d-%d-%d",&y,&m,&d);
x=y-1949;
if(x>0)
{
switch(m-1)
{
case 11:d1+=30;
case 10:d1+=31;
case 9:d1+=30;
case 8:d1+=31;
case 7:d1+=31;
case 6:d1+=30;
case 5:d1+=31;
case 4:d1+=30;
case 3:d1+=31;
case 2:d1+=28;
case 1:d1+=31;break;
}
if(m>2&&y%4==0&&y%100!=0||y%400==0)
d1++;
d2=(x-1)*365;
if(x/4>1)
d2+=x/4;
d3=91;
day=d1+d2+d3+d;
}
else
{
if(m-10>0)
{
switch(m-1)
{
case 11:d1+=60;break;
case 10:d1+=30;break;
}
day=d1+d;
}
else
day=d-1;
}
printf("%d\n",day);
}