题目:
https://www.luogu.org/problem/show?pid=1202
在洛谷,这个题只有入门难度;
但我调了两个多小时;
主要原因在于我只是用gdb调试和用肉眼看;
而对于这种题,最好的调试方法是输出中间变量;
适当的标识汉字有利于调试;
我并不觉得做简单题是在消磨时间;
相反,A掉这道题,我很开心,甚至比做出理论上比这难几十倍的题后更开心;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,num,cnt[12];
int a[1001][13];
int ss=0;
bool pdnian(int x)
{
if(!(x%100))
{
if(!(x%400)) return true;
else return false;
}
else
{
if(!(x%4)) return true;
else return false;
}
}
void ji(int x)
{
int tot=x-1900;
a[tot][4]=a[tot][6]=a[tot][9]=a[tot][11]=30;
if(pdnian(x)) a[tot][2]=29;
else a[tot][2]=28;
a[tot][1]=a[tot][3]=a[tot][5]=a[tot][7]=a[tot][8]=a[tot][10]=a[tot][12]=31;
return;
}
void solve()
{
scanf("%d",&n);
for(int i=1900;i<=1900+n-1;i++)
{
ji(i);
// cout<<i<<" ";
// for(int j=1;j<=12;j++) cout<<a[i-1900][j]<<" ";
// cout<<endl;
}
//预处理出天数,及是否是闰年;
num=1;//第一天是星期一;
for(int i=1900;i<=1900+n-1;i++)
{
int x=i-1900;//获取当前的年数;
for(int j=1;j<=12;j++)
{
ss=a[x][j];
// cout<<"年份 :"<<i<<" 月份:"<<j<<" 第一天星期 :"<<num;
int c=(num+12)%7;
cnt[c]++;
num=(num+ss)%7;
// cout<<" 十三号星期"<<c<<" 有"<<ss<<"天"<<endl;
}
}
cout<<cnt[6]<<" ";
for(int i=0;i<=5;i++) cout<<cnt[i]<<" ";
return;
}
int main()
{
solve();
return 0;
}