题目要求:题目描述:    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.到底是为什么呢?没有错误数据,实在发现不了哪错了.

解决方案 »

  1.   

    不是只输出了星期几吗,怎么会东西多呢? 你看你写了多少个out.. 
      

  2.   

    输入9 October 2001
    输出:20011009
             Tue Oct 09 00:00:00 CST 2001
              Tuesday输出了三行,题目只要最后一行.
      

  3.   

    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