代码 C++ (+O2)
#include<bits/stdc++.h>
using namespace std;
int Month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n, now = 1;
int day=1, month=1, year=1990;
int Week[8];
int Nextday1()
{
return now==7?1:now+1;
}
int Nextmonth()
{
if(month==12)
{
year ++;
return 1;
}
return month + 1;
}
int Nextday2()
{
if(day==Month[month])
{
month = Nextmonth();
return 1;
}
return day + 1;
}
bool isRun()
{
if(year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
return 1;
return 0;
}
int main()
{
cin >> n;
while(year < 1990 + n)
{
isRun()?Month[2] = 29:Month[2] = 28;
now = Nextday1();
day = Nextday2();
if(day == 13)
Week[now] ++;
}
cout << Week[6] << " " << Week[7] << " " << Week[1] << " " << Week[2] << " " << Week[3] << " " << Week[4] << " " << Week[5] << " ";
return 0;
}
求调~~~