求助求助,Java在线编程题,在线调试通不过用例(程序输出是空的)
然而本地IDE输出正确,自测复制粘贴输入输出,也能通过,为什么?代码如下
import java.util.*; import java.math.BigDecimal; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int l = in.nextInt(); ArrayList<Long> coord = new ArrayList<>(); for(int j = 0; j < n; j++){ coord.add(in.nextLong()); } Collections.sort(coord); Long max = Math.max(coord.get(0), l-coord.get(n-1))*2; for(int j = 0; j < n-1 ; j++){ if(coord.get(j+1)-coord.get(j)>max){ max = coord.get(j+1)-coord.get(j); } } Double d = (double)max/2; BigDecimal b = new BigDecimal(d); System.out.println(b.setScale(2)); } }然后我查看了通过的代码,和我的差别很小啊。。
importjava.util.Scanner;
importjava.math.BigDecimal;
publicclassMain{
publicstaticvoidmain(String[] args){
Scanner in = newScanner(System.in);
while(in.hasNext()){
intn = in.nextInt();
longl = in.nextLong();
long[] array = newlong[n];
for(inti=0;i<n;i++){
array[i] = in.nextLong();
}
for(inti=0;i<n;i++){
for(intj=0;j<n-i-1;j++){
if(array[j]>array[j+1]){
longtemp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
longmaxLength = 0;
for(inti=1;i<n;i++){
if(array[i]-array[i-1] > maxLength){
maxLength = array[i]-array[i-1];
}
}
maxLength = ((array[0]-0)*2> maxLength)?(array[0]-0)*2:maxLength;
maxLength = ((l-array[n-1])*2> maxLength)?(l-array[n-1])*2:maxLength;
doublereusult=(double)maxLength/2;
BigDecimal bigDecimal=newBigDecimal(reusult);
System.out.println(bigDecimal.setScale(2));
}
}
}
全部评论
(1) 回帖