HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)

Problem Description
Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me what day it is ?

Input
There are multiply cases.
One line is one case.
There are three integers, year(0< year<10000), month(0<=month<13), day(0<=day<32).

Output
Output one line.
if the date is illegal, you should output “illegal”. Or, you should output what day it is.

Sample Input
2007 11 17

Sample Output
Saturday

这个题目的某个日期是星期几,和真正的日历是不一样的!!!
所以,用Java的日期类Calendar是过不了的。
只能自己写囖。。。题目意思是:1 1 1是星期一!
而事实上,1 1 1是星期六。不要问我为什么,我也不知道。。。

package cn.hncu.acm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public class P2133 {

    public static void main(String[] args) throws ParseException {
        String[] week = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
        int yuee[][]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int y = sc.nextInt();
            int m = sc.nextInt();
            int d = sc.nextInt();
             if((yunn(y)==0&&m==2&&d==29)||m>12||d>yuee[yunn(y)][m]||m==0||d==0||y==0)
               {
                   System.out.println("illegal");
                   continue;
               }
             /*
            //题目是有问题的
            //1 1 1 应该是星期六,具体为什么看网上资料。
            //这个题目要求已知1 1 1是星期一
            String[] week = {"","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
            String strTime = y+"-"+m+"-"+d;
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(format.parse(strTime));
            System.out.println(week[c.get(Calendar.DAY_OF_WEEK)]);

            */
             int s=0;
             for(int i=1;i<y;i++){
                 if(yunn(i)==1){
                     s+=366;
                 }else{
                     s+=365;
                 }
             }

             for(int i=1;i<m;i++){
                 s+=yuee[yunn(y)][i];
             }
             s+=d;
             s=s%7;
             System.out.println(week[s]);
        }
    }

    public static int yunn(int xx)
    {
        if((xx%4==0&&xx%100!=0)||(xx%400==0))
            return 1;//是闰年
        return 0;//不是闰年
    }
}
时间: 2024-07-31 14:40:47

HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)的相关文章

HDOJ/HDU 1161 Eddy&amp;#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t

HDOJ(HDU) 2061 Treasure the new start, freshmen!(水题、)

Problem Description background: A new semester comes , and the HDU also meets its 50th birthday. No matter what's your major, the only thing I want to tell you is:"Treasure the college life and seize the time." Most people thought that the colle

HDOJ(HDU) 2109 Fighting for HDU(简单排序比较)

Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合各种ACM算法生成的老鼠药效果奇好,据说该药专对老鼠有效,如果被人误食了,没有任何副作用,甚至有传闻说还有健胃的效果,不过这倒没有得到临床验证.所以,公司的销量逐年递增,利润也是节节攀升,作为股东之一的公主负责财务,最近半年,她实在辛苦,多次因为点钞票造成双手抽筋而住院,现在在她面前你根本不要提到"

HDOJ(HDU) 2107 Founding of HDU(找最大值)

Problem Description 经过慎重的考虑,XHD,8600, LL,Linle以及RPG等ACM队员集体退役,甚至正在酝酿退学. 为什么?要考研?那也不用退学呀- 当然不是!真正的原因是他们想提前创业,想合伙成立一家公司,据说公司的名称都想好了,为了感谢多年的ACM集训队队长XHD,公司就叫海东集团(HaiDong Union),简称HDU.(对于这个公司名称,几个人私下里开玩笑说,外面的人看到HDU,可别以为是"胡捣集团",呵呵) 公司成立了,谁来做老大呢?这对于合伙的

HDOJ(HDU) 2500 做一个正气的杭电人(水~)

Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输出指定大小的"HDU"字符串,特别地,为了体现"正气"二字,我们要求输出的字符串也是正方形的(行数和列数相等). Input 输入的第一行包含一个正整数N(N<=20),表示一共有N组数据,接着是N行数据,每行包含一个正整数M(M<=50),表示一行内有M个

HDOJ(HDU) 1491 Octorber 21st

Problem Description HDU's 50th birthday, on Octorber 21st, is coming. What an exciting day!! As a student of HDU, I always want to know how many days are there between today and Octorber 21st.So, write a problem and tell me the answer.Of course, the

HDOJ(HDU) 1465 不容易系列之一(错排)

Problem Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的.比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情.如果套用一句经典的评语,我们可以这样总结

HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)

Problem Description 在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用'1'算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?   Input 测试数据有多行,每一行为一个数N(1<=N