poj3393

这是一道简单的模拟题,读懂题意。。。具体代码如下:

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值