九度oj 1043结果出错

lym152898 2017-02-22 05:55:59
题目要求:

题目描述:

We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.

输入:

There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.

输出:

Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

样例输入:

9 October 2001
14 October 2001

样例输出:

Tuesday
Sunday

提示:

Month and Week name in Input/Output:
January, February, March, April, May, June, July, August, September, October, November, December
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday


import java.util.Date;
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class MyDate{
public static final String [] MONTH = new String []{
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
public static int getMonth(String month){
for(int i = 1; i < 13; i++){
if(MONTH[i].equals(month)){
return i;
}
}
return -1;
}
}

public class TestDemo{
public static void main(String [] args) throws ParseException{
Scanner cin = new Scanner(System.in);
while(cin.hasNext()){
int temp = cin.nextInt();
String day;
if(temp < 10){
day = "0" + temp;
}
else{
day = "" + temp;
}
String month;
temp = MyDate.getMonth(cin.next());
if( temp < 10){
month = "0" + temp;
}
else{
month = temp + "";
}
String year = cin.next();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println(year + month + day);
Date date = sdf.parse(year + month + day);
System.out.println(date);
String [] word = date.toString().split(" ");
if("Mon".equals(word[0])){
System.out.println("Monday");
}
if("Tue".equals(word[0])){
System.out.println("Tuesday");
}
if("Wed".equals(word[0])){
System.out.println("Wednesday");
}
if("Thu".equals(word[0])){
System.out.println("Thursday");
}
if("Fri".equals(word[0])){
System.out.println("Friday");
}
if("Sat".equals(word[0])){
System.out.println("Saturday");
}
if("Sun".equals(word[0])){
System.out.println("Sunday");
}
}
}
}


测试数据都对了,可是提交了,一直是Wrong Answer.到底是为什么呢?没有错误数据,实在发现不了哪错了.
...全文
271 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lym152898 2017-03-02
  • 打赏
  • 举报
回复
import java.util.Date;
import java.util.Scanner;
import java.text.ParseException;
import java.text.SimpleDateFormat;
class MyDate{
    public static final String [] MONTH = new String []{
            "",
            "January",
            "February",
            "March",
            "April",
            "May",
            "June",
            "July",
            "August",
            "September",
            "October",
            "November",
            "December"
    };
    public static int getMonth(String month){
        for(int i = 1; i < 13; i++){
            if(MONTH[i].equals(month)){
                return i;
            }
        }
        return -1;
    }
}
  
public class TestDemo{
    public static void main(String [] args) throws ParseException{
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()){
            int temp = cin.nextInt();
            String day;
            if(temp < 10){
                day = "0" + temp;
            }
            else{
                day = "" + temp;
            }
            String month;
            temp = MyDate.getMonth(cin.next());
            if( temp < 10){
                month = "0" + temp; 
            }
            else{
                 month = temp + "";
            }
            String year = cin.next();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            Date date = sdf.parse(year + month + day);
            String [] word = date.toString().split(" ");
            if("Mon".equals(word[0])){
                System.out.println("Monday");
            }
            if("Tue".equals(word[0])){
                System.out.println("Tuesday");
            }
            if("Wed".equals(word[0])){
                System.out.println("Wednesday");
            }
            if("Thu".equals(word[0])){
                System.out.println("Thursday");
            }
            if("Fri".equals(word[0])){
                System.out.println("Friday");
            }
            if("Sat".equals(word[0])){
                System.out.println("Saturday");
            }
            if("Sun".equals(word[0])){
                System.out.println("Sunday");
            }
        }
    }
}
不好意思,之前调试忘了删掉多余的输出信息了,只输出星期时,结果还是Wrong Answer.实在是找不出问题在哪,测试过很多数据,结果都是正确的,可是提交之后就是不能AC
lym152898 2017-03-01
  • 打赏
  • 举报
回复
引用 1 楼 qq_35209952 的回复:
你输出的东西太多了吧
不是只输出了星期几吗,怎么会东西多呢?
_long_ 2017-03-01
  • 打赏
  • 举报
回复
输入9 October 2001 输出:20011009 Tue Oct 09 00:00:00 CST 2001 Tuesday 输出了三行,题目只要最后一行.
_long_ 2017-03-01
  • 打赏
  • 举报
回复
题目只让你回答星期几把,你把那天的信息都给输出了,会不会和这个有关系.
逗泥丸的平方 2017-03-01
  • 打赏
  • 举报
回复
引用 2 楼 lym152898 的回复:
[quote=引用 1 楼 qq_35209952 的回复:] 你输出的东西太多了吧
不是只输出了星期几吗,怎么会东西多呢?[/quote] 你看你写了多少个out..
逗泥丸的平方 2017-02-23
  • 打赏
  • 举报
回复
你输出的东西太多了吧

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧