CCF认证 201503-3节日

被令人恐惧的力量支配,每道题都只拿90分,慌得不行,我是不是该换语言了。。。

思路

先算出当前年的1月1号,距离baseYear多少天(方便算出星期几)再算出该年的a月1号,距离baseYear的1月1号多少天。最后根据第几个星期几,求一下多少天。

当时脑子抽了,以为1月1号是星期四 , 那么就没有第1个星期三,因此40分。
最后还是不能得100,不知道为啥

代码
import java.util.Scanner;


public class Main{

    private static Scanner cin;

    public static  int []months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    public static void main(String[] args) {
        cin = new Scanner(System.in);
        int a ,b,c,y1,y2;
        a = cin.nextInt();
        b = cin.nextInt();
        c = cin.nextInt();
        y1 = cin.nextInt();
        y2 = cin.nextInt();

        int day = 0,y;
        // 得到2014年1月1日到1850年1月1日共几天
        for(y = 1850;y<y1;y++){
            if(isRun(y))
                day += 366;
            else day += 365;
        }
        // 得到a月1号 到初始值共几天
        for(;y<=y2;y++){
            int tmpDay = day;
            for(int m = 1; m < a; m++){
                if(m == 2 && isRun(y)){
                    tmpDay += 29;
                }else
                    tmpDay += months[m];
            }
            int weekDay = (tmpDay%7+2)%7;
            if(weekDay == 0)
                weekDay = 7;
           // System.out.println(a+" 月的1号是 "+weekDay);
            int needDay;
            if(c >= weekDay)
                needDay = (b-1)*7 + c - weekDay+1;
            else
                needDay = (b-1)*7 + c + 7 - weekDay + 1;
            if(needDay>months[a])
                System.out.println("none");
            else {
                String output = y + "/";
                if (a < 10)
                    output += "0";
                output += a + "/";
                if (needDay < 10)
                    output += "0";
                output += needDay;
                System.out.println(output);
            }
            day += 365;
            if(isRun(y))
                day ++;
        }
    }
    static boolean isRun(int y){
        if(y%400 == 0)
            return true;
        if(y%4==0 && y%100 != 0)
            return true;
        return false;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值