개발자 톡
왜 틀렸는지 모르겠습니다 (JAVA) ;;
- 등록일
- 2024-10-30 13:15:15
- 조회수
- 75
- 작성자
- taylor7418
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] NK = br.readLine().split(" ");
int N = Integer.parseInt(NK[0]);
int K = Integer.parseInt(NK[1]);
String [] scores = br.readLine().split(" ");
int [] sumScores = new int[N];
sumScores[0] = Integer.parseInt(scores[0]);
for(int i=1; i<N; i++){
sumScores[i] = sumScores[i-1] + Integer.parseInt(scores[i]);
}
for(int i=0; i<K; i++){
String [] ab = br.readLine().split(" ");
int a = Integer.parseInt(ab[0]);
int b = Integer.parseInt(ab[1]);
if(a == 1){
double result = sumScores[b-1]/((b-a+1)*1.0);
System.out.println(String.format("%.2f",result));
}else{
double result = (sumScores[b-1]-sumScores[a-2])/(b-a+1);
System.out.println(String.format("%.2f",result));
}
}
}
}
왜 틀릴까요 저에게 이유를 알려주세요