Description
wjw最近运气极其差,什么roll点1-100连着十次都是个位数啊,买个珍珠奶茶没有珍珠啊,吃方便面没有调料包啊…
迷信的wjw觉得,一定是因为这个月的13号正好是星期五,才会导致他的运气这么差。
现在他想知道,在某个年份中,有多少个月的13号是星期五,这样他才可以提前做好心理准备。
PS.已知1998年1月1日是星期四,输入的年份肯定大于或等于1998年。
Input
input
输入只有一行,表示年份(大于等于1998年)
Output
output
输出只有一行,表示这一年中有多少个月的13号是星期五
Sample Input
Copy
1998
Sample Output Copy
3
HINT
说明:(1)一年有365天,闰年有366天,所谓闰年,即能被4整除且不能被100整除的年份,或是既能被100整除也能被400整除的年份;
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//基姆拉尔森计算公式
int Solve(int y,int m,int d){
if((m==1)||(m==2)){
m+=12;
y--;
}
return (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7+1;
}
int main()
{
int y;
while(cin>>y){
int sum=0;
for(int m=1;m<=12;m++){
int x=Solve(y,m,13);
if(x==5)
sum++;
//printf("%d\n",x);
}
cout <<sum<< endl;
}
return 0;
}