节日

来源:互联网 发布:腾讯与巨人网络 编辑:程序博客网 时间:2024/04/28 13:00

问题描述
试题编号: 201503-3
试题名称: 节日
时间限制: 1.0s
内存限制: 256.0MB
问题描述:
问题描述
  有一类节日的日期并不是固定的,而是以“a月的第b个星期c”的形式定下来的,比如说母亲节就定为每年的五月的第二个星期日。
  现在,给你a,b,c和y1, y2(1850 ≤ y1, y2 ≤ 2050),希望你输出从公元y1年到公元y2年间的每年的a月的第b个星期c的日期。
  提示:关于闰年的规则:年份是400的整数倍时是闰年,否则年份是4的倍数并且不是100的倍数时是闰年,其他年份都不是闰年。例如1900年就不是闰年,而2000年是闰年。
  为了方便你推算,已知1850年1月1日是星期二。
输入格式
  输入包含恰好一行,有五个整数a, b, c, y1, y2。其中c=1, 2, ……, 6, 7分别表示星期一、二、……、六、日。
输出格式
  对于y1和y2之间的每一个年份,包括y1和y2,按照年份从小到大的顺序输出一行。
  如果该年的a月第b个星期c确实存在,则以”yyyy/mm/dd”的格式输出,即输出四位数的年份,两位数的月份,两位数的日期,中间用斜杠“/”分隔,位数不足时前补零。
  如果该年的a月第b个星期c并不存在,则输出”none”(不包含双引号)。
样例输入
5 2 7 2014 2015
样例输出
2014/05/11
2015/05/10
评测用例规模与约定
  所有评测用例都满足:1 ≤ a ≤ 12,1 ≤ b ≤ 5,1 ≤ c ≤ 7,1850 ≤ y1, y2 ≤ 2050。
本题目提交分数为80分。

package geekfly.test;/* * 80分,未通过 */import java.util.Scanner;public class 节日 {    private static int mounth[] = new int[]{31,28,31,30,31,30,31,31,30,31,30,31},week=0,temp=0,total = 2;    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),y1 = sc.nextInt(),y2 = sc.nextInt();        for (int i = 1850; i < y1; i++) {            if((i%4==0&&i%100!=0)||i%400==0)                total +=366;            else                total += 365;        }        for(int i=y1;i<=y2;i++){            int y = getWeek(a,i);            int x = c - y,day=1;            if(x>0){                day = day +(b-1)*7 + x;            }else if(x==0){                day = day +(b-1)*7 ;            }else{                day = day + (b-1)*7 + c + 7 - y;            }            if(day>mounth[a-1])                System.out.println("none");            else{                if(a>9)                 System.out.println(i+"/"+a+"/"+day);                else                  System.out.println(i+"/0"+a+"/"+day);            }        }    }     public static int getWeek(int num,int year){         week = total%7==0? 7:total%7;         int days = week;         if((year%4==0&&year%100!=0)||year%400==0){                mounth[1] = 29;                total += 366;         }else{            mounth[1] = 28;            total += 365;        }         for (int i = 0; i < num-1; i++) {            days += mounth[i];        }         return (days%7==0)? 7:days%7;    }}
0 0