소수점이 문제인가 싶어 힌트에서 처럼 소수점 3째자리만 나오도록 했다.
근데 왜 틀렸지?????
??????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static double alcol[];
static double sum[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int l = Integer.parseInt(st.nextToken());
alcol = new double[n];
sum = new double[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
int alco = Integer.parseInt(st.nextToken());
alcol[i] = Math.round(alco * 0.001 * 1000) / 1000.0;
System.out.println(alcol[i]);
}
sum[0] = alcol[0];
for (int i = 1; i < l; i++) {
sum[i] = sum[i - 1] + alcol[i];
}
for (int i = l; i < n; i++) {
int j = i - l;
sum[i] = sum[i - 1] - alcol[j];
sum[i] = sum[i] + alcol[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (sum[i] >= 0.129 && sum[i] <= 0.138) {
cnt++;
}
}
System.out.println(cnt);
}
}
값을 그냥 정수로 바꿔줬는데 맞았다.
실수 연산을 하면 나눌 때 오차가 조금씩 생격서 그런 거 같다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static double alcol[];
static double sum[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int l = Integer.parseInt(st.nextToken());
alcol = new double[n];
sum = new double[n];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
int alco = Integer.parseInt(st.nextToken());
alcol[i] = alco;
}
sum[0] = alcol[0];
for (int i = 1; i < l; i++) {
sum[i] = sum[i - 1] + alcol[i];
}
for (int i = l; i < n; i++) {
int j = i - l;
sum[i] = sum[i - 1] - alcol[j];
sum[i] = sum[i] + alcol[i];
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (sum[i] >= 129 && sum[i] <= 138) {
cnt++;
}
}
System.out.println(cnt);
}
}