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

举报
谙忆 发表于 2021/05/26 16:19:18 2021/05/26
【摘要】 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 thr...

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;//不是闰年 }
}

  
 
  • 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
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

文章来源: chenhx.blog.csdn.net,作者:谙忆,版权归原作者所有,如需转载,请联系作者。

原文链接:chenhx.blog.csdn.net/article/details/51306732

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。