本地输出没问题。
#include<bits/stdc++.h>
using namespace std ;
int pn[13] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
int rn[13] = { 0 , 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;
long long n , x , a[7] , y = 1900 ;
int main ()
{
std::ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
cin >> n ;
for ( int i = 0 ; i < n ; i++ )
{
y ++ ; //年份
if ( ( y % 4 == 0 && y % 100 != 0 ) || ( y % 400 == 0 && y % 100 == 0 ) ) //判断闰年
{
for ( int j = 1 ; j < 13 ; j ++ ) //加一轮
{
x += 13 ; //总日期加13
if ( x % 7 == 0 ) a[7] ++ ; // 特判如果13日是周日的时候
else a[ x % 7 ] ++ ; //星期几的计数数组根据总日期现在到了哪里再加
x += ( rn[j] - 13 ) ; //完成后再加上当月剩余的日期
}
}
else //平年
{
for ( int j = 1 ; j <= 12 ; j ++ ) //加一轮
{
x += 13 ;
if ( x % 7 == 0 ) a[7] ++ ;
a[ x % 7 ] ++ ;
x += ( pn[j] - 13 ) ;
}
}
}
cout<< a[6] << " " << a[7] << " " ;
for ( int i = 1 ; i <= 5 ; i ++ )
cout << a[i] << " " ;
return 0 ;
}