zoukankan      html  css  js  c++  java
  • 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;//不是闰年
        }
    }
    
  • 相关阅读:
    2.ECMAScript 5.0
    1.Javascript简介
    9.定位
    HDU2032 杨辉三角
    HDU2058 The sum problem
    HDU2091 空心三角形
    HDU1166 敌兵布阵(树状数组模板题)
    HDU2049 不容易系列之(4)——考新郎
    Python网络爬虫与信息提取(三)(正则表达式的基础语法)
    HDU6576 Worker
  • 原文地址:https://www.cnblogs.com/webmen/p/5739232.html
Copyright © 2011-2022 走看看