题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.util.Arrays.*;
import static java.util.stream.Stream.*;
public class Main {
public static void main(String[] args) throws IOException {
testTh();
}
private static void testTh() throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str;
ArrayList<String>s = new ArrayList<>();
while ((str = bf.readLine()) != null) {
s.add(str);
if (str.equals("\n"))break;
}
int[] temp = new int[s.size()];
int i = 0;
int count = 0;
for (String s1 : s) {
int parseInt = Integer.parseInt(s1);
if (parseInt < 0) {
count++;
} else if (parseInt == 0) {
continue;
} else {
temp[i] = parseInt;
i++;
}
}
int res = 0;
int flag = 0;
for (int j = 0; j < temp.length; j++) {
if (temp[j] == 0)break;
res = res + temp[j];
flag++;
}
if (flag == 0) {
System.out.println(count);
System.out.println("0.0");
} else {
double avg = (double) res / flag;
DecimalFormat dateFormat = new DecimalFormat("#0.0");
System.out.println(count);
System.out.println(dateFormat.format(avg));
}
}
}
