bool runnian(int y)
{
return (y%4==0&&y%100!=0)||y%400==0;
}
int fm(int y,int m,int d)
{
switch (m)
{
case 1:
if(!runnian(y)) return -(9+31+30+31+30+31+28+31-d);
else return -(9+31+30+31+30+31+29+31-d);
break;
case 2:
if(!runnian(y)) return -(9+31+30+31+30+31+28-d);
else return -(9+31+30+31+30+31+29-d);
break;
case 3:
return -(9+31+30+31+30+31-d);
break;
case 4:
return -(9+31+30+31+30-d);
break;
case 5:
return -(9+31+30+31-d);
break;
case 6:
return -(9+31+30-d);
break;
case 7:
return-(9+31-d);
break;
case 8:
if(d>=9) return (d-9);
else return -(9-d);
break;
case 9:
return (22+d); break;
case 10:
return (22+30+d); break;
case 11:
return (22+30+31+d); break;
case 12:
return (22+30+31+30+d); break;
}
}
int f(int y,int m,int d)
{
int day=0;
if(y==2013) day=fm(y,m,d);
if(y<2013)
{
for (int i=2013;i>y;i--)
{
if(runnian(i)) day+=366;
else day+=365;
}
day-=fm(y,m,d);
day=-day;
}
if(y>2013)
{
for (int i=y;i>2013;i--)
{
if(runnian(i)) day+=366;
else day+=365;
}
day=day+fm(y,m,d);
}
if(day>=0)
return (5+day)%7==0?7:(5+day)%7;
else
return 5-(-day)%7>0?5-(-day)%7:5-(-day)%7+7;
}
void main()
{
cout<<f(20,8,8);
system("pause");
}