我是使用java編譯的,jdk版本是17,雖然跟這裡的jdk18不同,但這段代碼的編譯jdk18應該不可能出錯才對,而這種在eclipse上可以邊譯,但judge總是CE的問題我一直遇到。我尋找了諸多的途徑詢問,但總是被踢去其他地方問,或是不回答我,包括zerojudge管理員,這個問題我很怕也發生在apcs上,以下是我的代碼
package learning;
import java.util.*;
class item {
int weight;
int time;
int toto;
public item(int weight,int time) {
this.weight=weight;
this.time=time;
}
}
public class c471 {
public static List<item>stack=new ArrayList<>();
public static void main(String [] args) {
Scanner sc=new Scanner(System.in);
Scanner thes=new Scanner(System.in);
try {
int N=sc.nextInt();
String [] s=thes.nextLine().split(" ");
String [] s2=thes.nextLine().split(" ");
for(int i=0;i<N;i++) {
stack.add(new item(Integer.parseInt(s[i]),Integer.parseInt(s2[i])));
}
for (int j=0;j<N;j++)
for (int i=0;i<N-1;i++) {
if (stack.get(i).time*stack.get(i).weight>stack.get(i+1).time*stack.get(i).weight) {
item temp=stack.get(i+1);
stack.remove(i+1);
stack.add(i,temp);
}
}
int sum=0;
int total=0;
for (int i=0;i<N;i++) {
stack.get(i).toto=sum*stack.get(i).time;
sum+=stack.get(i).weight;
total+=stack.get(i).toto;
}
System.out.println(total);
}finally {sc.close();thes.close();}
}
}
這段代碼在eclipse和cmd都能正常邊譯
結果judge給我輸出這樣的結果:
/12003267/item.java:11: error: class c471 is public, should be declared in a file named c471.java public class c471 { ^ 1 error
我的資料夾是這樣的
所以有人知道這為甚麼不能編譯嗎
把class c471放到class item前面