首页 > 专题系列 > Java解POJ > POJ 3047 Bovine Birthday [解题报告] Java
2013
11-12

POJ 3047 Bovine Birthday [解题报告] Java

Bovine Birthday

问题描述 :

Bessie asked her friend what day of the week she was born on. She knew that she was born on 2003 May 25, but didn’t know what day it was. Write a program to help. Note that no cow was born earlier than the year 1800.

Facts to know:

* January 1, 1900 was on a Monday.

* Lengths of months:

    Jan 31          May 31      Sep 30
Feb 28 or 29 Jun 30 Oct 31
Mar 31 Jul 31 Nov 30
Apr 30 Aug 31 Dec 31

* Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year).

* The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.

输入:

* Line 1: Three space-separated integers that represent respectively the year, month (range 1..12), and day of a date.

输出:

* Line 1: A single word that is the day of the week of the specified date (from the lower-case list: monday, tuesday, wednesday, thursday, friday, saturday, sunday).

样例输入:

2003 5 25

样例输出:

sunday

温馨提示:

INPUT DETAILS:

May 25, 2003

OUTPUT DETAILS:

      May 2003
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

解题代码:

//* @author: 
import java.util.Scanner;
import java.util.Arrays;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    String  s[]={"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"};
    int n,y,m,d,t;
    y=sc.nextInt();
    m=sc.nextInt();
    d=sc.nextInt();
    t=(y-1)*365;
    for (int i=1;i< y;i++) if ((i%4==0&&i%100!=0)||(i%400==0)) t++;
    if ((y%4==0&&y%100!=0)||(y%400==0)) a[2]++;
    for (int i=1;i< m;i++) t+=a[i];
    t+=d+6;
    System.out.println(s[t%7]);
 }
}

  1. “可以发现,树将是满二叉树,”这句话不对吧,构造的树应该是“完全二叉树”,而非“满二叉树”。