首页 > 代码库 > 今天是星期几
今天是星期几
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int arry[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool is_bisse(int year)
{
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
return 0;
}
int get_day(int year, int mon, int day)
{
int sum = 0;
for(int i = 1; i < year; i++)
{
sum += 365;
if(is_bisse(i))
sum++;
}
for(int i = 1; i < mon; i++)
sum += arry[i];
if(mon > 2 && is_bisse(year))
sum++;
sum += day;
sum %= 7;
if(sum == 0) sum = 7;
return sum;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int year, mon, day;
scanf("%d %d %d", &year, &mon, &day);
printf("%d\n", get_day(year, mon, day));
}
}
今天是星期几