这是一道简单的模拟题,读懂题意。。。具体代码如下:
#include<stdio.h>
#include<stdlib.h>
int y1,m1,y2,m2;
int nmon[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int mon[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
int week[7] = {7,1,2,3,4,5,6};
int yes(int x)
{
if(x < 1582){
if(x%4 == 0) return 1;
else return 0;
}else if(x >= 1582){
if(x == 1700) return 1;
if((x%4==0)&&((x%100)!=0)||(x%400 == 0)) return 1;
else return 0;
}
}
int count(int y1,int m1,int y2,int m2)
{
int i,j,day = 1;
if(y1 > 1752) day -= 11;
else if(y1 == 1752&&m1>9) day -= 11;
for(i = 1; i < y1;i++){
if(yes(i)) day += 366;
else day += 365;
}
if(yes(y1)){
for(i = 1;i < m1;i ++)
day += mon[i];
}else{
for(i = 1; i < m1;i++)
day += nmon[i];
}
return day;
}
int main()
{
int cas,i,j;
int go,luc,day;
scanf("%d",&cas);
while(cas--){
go = 0;
luc = 0;
scanf("%d %d %d %d",&y1,&m1,&y2,&m2);
int countday = count(y1,m1,y2,m2);
if(((countday+5)%7 == 1)||((countday+5)%7)==6||((countday+5)%7==0)) go++;
for(i = y1;i < y2;i++){
if(i == y1) j = m1;
else j = 1;
for(;j<=12;j++){
if(yes(i)){
countday += mon[j];
}else{
countday += nmon[j];
}
if(i==1752&&j==9) countday -= 11;
if(((countday+5)%7==1)||((countday+5)%7 == 6)||((countday+5)%7)==0){
go++;
luc++;
}
}
}
if(y1 == y2) j = m1;
else j = 1;
for(;j<=m2;j++){
if(yes(y2)){
countday += mon[j];
}else{
countday += nmon[j];
}
if(y2==1752&&j==9) countday -= 11;
if(((countday+5)%7==1)||((countday+5)%7 == 6)||((countday+5)%7)==0){
if(j != m2){go++;
}
luc++;
}
}
printf("%d %d\n",luc,go);
}
return 0;
}