USACO打印问题:无法找到/加载主类

时间:2018-12-29 20:39:50

标签: java

在我的计算机上,该程序使用正确的解决方案成功写入了名为friday.out的文件。但是,USACO网站告诉我“错误:_Could_not_find_or_load_main_class_friday”。

我尝试过公开授课,并删除了public一词(没有区别)。该程序编译没有任何错误。

package friday;
import java.io.*;
import java.util.*;
class friday {

    static boolean leapYear = false; //Are we on a leap year
    public static boolean leapYearTest(int year) {
        if(year%100==0 && year%400==0) {
            leapYear = true;
        }
        else if(year%100==0 && year%400 != 0) {
            leapYear = false;
        }
        else if(year%100!=0 && year%4==0) {
            leapYear = true;
        }
        else if(year%100!=0 && year%4!=0) {
            leapYear = false;
        }
        return leapYear;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new FileReader("friday.in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("friday.out")));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int years = Integer.parseInt(st.nextToken()); //Number of years
        int endYear = 1900+years-1;
        int currentYear = 1900;
        int currentDay = 1; //Jan 1. day = 1
        int currentMonth = 1; //Jan = 1, Feb = 2, etc.
        int currentStringDay = 1; //Mon = 1, Tues = 2, etc.
        int totalDays = 0;
        //For loop figures out number of days
        for(int i=1900;i<=endYear;i++) {
            if(leapYearTest(i)==true) {
                totalDays+=366;
            }
            else if(leapYearTest(i)==false) {
                totalDays+=365;
            }
        }
        //End for loop
        HashMap<Integer,Integer> regMonths = new HashMap<Integer,Integer>();
        regMonths.put(1, 31);
        regMonths.put(2, 28);
        regMonths.put(3, 31);
        regMonths.put(4, 30);
        regMonths.put(5, 31);
        regMonths.put(6, 30);
        regMonths.put(7, 31);
        regMonths.put(8, 31);
        regMonths.put(9, 30);
        regMonths.put(10, 31);
        regMonths.put(11, 30);
        regMonths.put(12, 31);
        HashMap<Integer,Integer> leapMonths = new HashMap<Integer,Integer>();
        leapMonths.put(1, 31);
        leapMonths.put(2, 29);
        leapMonths.put(3, 31);
        leapMonths.put(4, 30);
        leapMonths.put(5, 31);
        leapMonths.put(6, 30);
        leapMonths.put(7, 31);
        leapMonths.put(8, 31);
        leapMonths.put(9, 30);
        leapMonths.put(10, 31);
        leapMonths.put(11, 30);
        leapMonths.put(12, 31);
        int SatCounter = 0; //Saturday Counter
        int SunCounter = 0;
        int MonCounter = 0;
        int TuesCounter = 0;
        int WedCounter = 0;
        int ThurCounter = 0;
        int FriCounter = 0;
        for(int i = currentDay;i<=totalDays;i++) {
            if(i%7==0) {
                currentStringDay=7;
            }
            else if(i%7!=0) {
                currentStringDay=i%7;
            }
            //if(currentDay == 13 && currentStringDay == 5) {
            if(currentDay == 13) {
                if(currentStringDay == 6) {
                    SatCounter+=1;
                }
                if(currentStringDay == 7) {
                    SunCounter+=1;
                }
                if(currentStringDay == 1) {
                    MonCounter+=1;
                }
                if(currentStringDay == 2) {
                    TuesCounter +=1;
                }
                if(currentStringDay == 3) {
                    WedCounter+=1;
                }
                if(currentStringDay == 4) {
                    ThurCounter+=1;
                }
                if(currentStringDay == 5) {
                    FriCounter+=1;
                }

            }

            if(leapYearTest(currentYear)==false) {
                //use regMonths
                if(currentDay<regMonths.get(currentMonth)) {
                    currentDay+=1;
                }
                else if(currentDay==regMonths.get(currentMonth)) {
                    currentDay=1;
                    if(currentMonth<12) {
                        currentMonth+=1;
                    }
                    else if(currentMonth == 12) {
                        currentMonth = 1;
                    }
                    if(currentMonth == 1) {
                        currentYear+=1;
                        currentDay=1;
                    }
                }
            }
            else if(leapYearTest(currentYear)==true) {
                //use leapMonths
                if(currentDay<leapMonths.get(currentMonth)) {
                    currentDay+=1;
                }
                else if(currentDay==leapMonths.get(currentMonth)) {
                    currentDay=1;
                    if(currentMonth<12) {
                        currentMonth+=1;
                    }
                    else if(currentMonth == 12) {
                        currentMonth = 1;
                    }
                    if(currentMonth == 1) {
                        currentYear+=1;
                        currentDay=1;
                    }
                }
            }
        }
        out.println(SatCounter+" "+SunCounter+" "+MonCounter+" "+TuesCounter+" "+WedCounter+" "+ThurCounter+" "+FriCounter);
        out.close();
    }
}

1 个答案:

答案 0 :(得分:0)

只说杰伊的评论作为答案,因为它也对我有用。确保您的文件在班级顶部不包含package语句。