# 2850. 小强的生日

### include

using namespace std;
int getDay(int year, int month, int day)//返回任意一天是星期几
{
if (month == 1 || month == 2) year–;
int k = day;
int m = ((month - 2) + 12) % 12;
if (m == 0) m = 12;
int Y = year % 100;
int C = year / 100;
return ((k + int(2.6 * m - 0.2) - 2 * C + Y + int(Y/4) + int(C/4)) % 7 + 7) % 7;
}
bool run(int year)
{
if (year % 4 == 0 && year % 100 != 0) return true;
if (year % 400 == 0) return true;
return false;
}
int main()
{
int n;
while (~scanf(“%d”, &n))
{
int day = getDay(n, 2, 1);
puts(” SU MO TU WE TH FR SA”);
int cnt = 3 * day;
while (cnt–) putchar(‘ ‘);
cnt = 1;
int end = run(n) ? 29 : 28;
for (int i = 0,j = day; cnt <= end; j++)
{
if (j > 6)
{
j = 0;
i++;
puts(“”);
}
printf(“%3d”,cnt++);
}
puts(“”);
}
return 0;
}

#include <stdio.h>
int main(void)
{
int y, w;
while((scanf("%d",&y))!=EOF)
{
w=5;
if(y>2008)
w=(w+365*(y-2008)+(y-2009)/4+1)%7;
printf(" SU MO TU WE TH FR SA\n");
int i, d;
for(i=0; i<w; i++)
printf("   ");
if(y%4==0 && y!=2100) d=29;
else d=28;
for(i=1; i<=d; i++)
{
if(i<10) printf("  %d",i);
else printf(" %d",i);
if((i+w)%7==0) printf("\n");
}
if((--i+w)%7!=0) printf("\n");
printf("\n");
}
return 0;
}


### include

int main(void)
{
int y, w;
while((scanf(“%d”,&y))!=EOF)
{
w=5;
if(y>2008)
w=(w+365*(y-2008)+(y-2009)/4+1)%7;
printf(” SU MO TU WE TH FR SA\n”);
int i, d;
for(i=0; i<w; i++)
printf(” “);
if(y%4==0 && y!=2100) d=29;
else d=28;
for(i=1; i<=d; i++)
{
if(i<10) printf(” %d”,i);
else printf(” %d”,i);
if((i+w)%7==0) printf(“\n”);
}
if((–i+w)%7!=0) printf(“\n”);
printf(“\n”);
}
return 0;
}

1.闰年的判断
2.用+366/365 取模来计算二月一日是星期几
3.最终不用下划线，用空格
4.%3d的用法

### include

using namespace std;
int year;
int tu[10][10];
char tmp[10];
int isRUN(int aa)
{
if((aa%400==0) || (aa%4==0 && aa%100!=0)) return 1;
else return 0;
}
int cal(int aa)
{
int ret=6;
for(int i=2008;i<aa;i++)
{
ret=(ret-1+(isRUN(i)?366:365))%7+1;
}
return ret;
}
void Main()
{
int col=cal(year);

memset(tu,0,sizeof(tu));
int row=1;
for(int i=1;i<=(isRUN(year)?29:28);i++)
{
tu[row][col]=i;
if(col==7) {col=1;row++;}
else col++;
}
cout<<” SU MO TU WE TH FR SA”<>year) Main();
return 0;
}