根据一个日期直接计算那天是周几有一个公式:蔡勒公式
一重循环判断记录即可:
#include<iostream>
#include<cstring>
#include<sstream>
#include<string>
using namespace std;
string s;
void s2i(string s,int &num)
{
stringstream ss;
ss<<s;
ss>>num;
}
int main()
{
cin>>s;
int c=0;
int y=0;
s2i(s.substr(0,2),c);
s2i(s.substr(2,2),y);
int ans=0;
for(int m=1;m<=12;++m)
{
int month=m;
int year=y;;
if(m<3){
month=12+m;
year=y-1;
}
int w=(c/4)-2*c+year+(year/4)+(26*(month+1)/10)+13-1;
w=(w%7+7)%7;
if(w==5) ans++;
}
cout<<ans<<endl;
return 0;
}