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;//不是闰年
        }
    }
    
  • 相关阅读:
    Swift 泛型和闭包结合使用
    Swift中避免在多个文件中重复import相同的第三方包
    iOS AVAudioPlayer播放音频时声音太小
    python中装饰器的原理以及实现,
    python-网易云简单爬虫
    python模拟SQL语句操作文件
    python学习第二天-基本数据类型常用方法
    python学习第一天-语法学习
    iOS 出现错误reason: image not found的解决方案
    Swift as as!和as?的区别
  • 原文地址:https://www.cnblogs.com/webmen/p/5739232.html
Copyright © 2011-2022 走看看