给定2011年的月和日,求该日期是星期几。C++就直接用基姆拉尔森计算公式计算了,python就偷懒了,直接datetime+strftime输出了。
python版本AC代码
from time import strftime
from datetime import datetime
yy = 2011
testcase = int(input())
while testcase > 0:
testcase -= 1
mm,dd = map(int,input().split())
weekday=datetime(yy,mm,dd).strftime("%A")
print(weekday)
C++版本AC代码
#include <iostream>
#include<cstdio>
using namespace std;
//#define ZANGFONG
char week[7][20] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int main()
{
#ifdef ZANGFONG
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif // ZANGFONG
int testcase;
int d,m,y,yy,W;
scanf("%d\n",&testcase);
yy = 2011;
while(testcase--)
{
scanf("%d%d\n",&m,&d);
if(m < 3)
{
y = yy-1;
m += 12;
}
else y = yy;
W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400+1)%7; //C++计算公式
printf("%s\n",week[W]);
}
return 0;
}