第一行输入一个整数
代表整数的个数。
第二行输入
个整数
代表输入的整数。
先输出一个整数,代表负整数的个数;随后在同一行输出一个实数,代表正整数的平均值。
由于实数的计算存在误差,当误差的量级不超过
时,您的答案都将被接受。具体来说,设您的答案为
,标准答案为
,当且仅当
时,您的答案将被接受。
6 -1 3 -2 1 0 1
2 1.66666666667
3 0 0 0
0 0
本题输出要求已规范,允许细微误差(2025/01/16)。
遍历期间分别记录整正数、负数个数,以及正数的和。最后依次输出负数个数、输出正数和 / 正数个数,注意当整数个数为0时,直接输出0,避免除数为0报NAN
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int numbers = in.nextInt();
int minors0Num = 0;
int over0Nums = 0;
double average = 0.0;
for (int i = 0; i < numbers; i++){
int now = in.nextInt();
if (now < 0){
minors0Num++;
}else if (now > 0){
average += now;
over0Nums++;
}
}
if (over0Nums != 0){
System.out.println(minors0Num + " " + average / (over0Nums));
}else{
System.out.println(minors0Num + " " + 0);
}
}
}
} import java.util.*;
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int a = in.nextInt();
int count1=0;
int sum = 0;
int count2=0;
int count3 = 0;
for(int i=0;i<a;i++){
int b = in.nextInt();
if(b<0){
count1++;
}else if(b>0){
sum+=b;
count2++;
}else{
count3++;
}
}
double avg = (double)sum/count2;
if(count3 == a-count1){
System.out.println(count1+ " " + 0);
}else{
System.out.print(count1+ " "+ String.format("%.11f",avg));
}
}
} // 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int a = in.nextInt();
int count=0;
int sum = 0;
int count2=0;
for(int i=0;i<a;i++){
int b = in.nextInt();
if(b<0){
count++;
}else if(b>0){
sum+=b;
count2++;
}
}
double avg =0.0;
if(count2!=0){
avg = (double)sum/count2;
}
System.out.print(count+" "+String.format("%.1f",avg));
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int sum = 0;
int positiveNumber = 0;
int negativeNumber = 0;
for(int i= 0; i < a;i++){
int n = in.nextInt();
if(n > 0 && n != 0){
sum += n;
positiveNumber ++;
}else if (n < 0){
negativeNumber++;
}
}
double dou = 0;
if (positiveNumber != 0) {
dou = (double) sum/positiveNumber;
}
System.out.print(negativeNumber+" "+String.format("%.1f",dou));
}
}
} import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
ArrayList<Integer> list=new ArrayList<>();
int n=in.nextInt();
int sum=0;
for(int i=0;i<n;i++){
Integer tmp=Integer.valueOf(in.next());
if(tmp<0){
sum++;
}else if(tmp>0){
list.add(tmp);
}
}
Double result=0.0;
for(int i=0;i<list.size();i++){
result+=list.get(i);
}
if(list.size()==0){
System.out.print(sum+" "+0.0);
}else{
result=result/list.size();
System.out.print(sum+" "+String.format("%.1f",result));
}
}
} import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
while((str=br.readLine())!=null){
int cou=Integer.parseInt(str);
int[] dd=new int[cou];
String[] strArr=br.readLine().split(" ");
for(int i=0;i<cou;i++){
dd[i]=Integer.parseInt(strArr[i]);
}
int fu=0;
double sum=0.0;
int lin=0;
for(int i=0;i<cou;i++){
if(dd[i]<0){
fu++;
continue;
}else if(dd[i]==0){
lin++;
continue;
}
sum+=dd[i];
}
if(cou-fu-lin==0){
System.out.println(fu+" "+"0.0");
}else{
double s=sum/(cou-fu-lin);
//
System.out.println(fu+" "+String.format("%.1f",s));
}
}
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int[] ar = new int[length];
for (int i = 0; i < length; i++) {
ar[i] = scanner.nextInt();
}
int counts_=0;
int counts=0;int sum=0;
for (int i = 0; i < length; i++)
{
if(ar[i]>0) {sum+=ar[i];counts+=1;}
if(ar[i]<0) counts_+=1;
}
double avg= Math.round(sum*1.0/counts*10)*1.0/10;
System.out.println(counts_+" "+avg);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int[] ints = new int[n];
for (int i = 0; i < ints.length; i++) {
ints[i] = sc.nextInt();
}
solution(ints);
}
}
private static void solution(int[] ints) {
double avg = 0.0;
int countB = 0;
int countS = 0;
for (int anInt : ints) {
if (anInt > 0) {
avg += anInt;
countB++;
} else if (anInt < 0) {
countS++;
}
}
if (countB > 0) {
avg /= countB;
}
String avg1 = String.format("%.1f", avg);
System.out.println(countS + " " + avg1);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int s1 = 0,s2 = 0;
double sum = 0.0;
int[] arr = new int[n];
for(int i = 0;i<n;i++){
arr[i] = sc.nextInt();
}
for(int i = 0;i<arr.length;i++){
if(arr[i] <0)
s1++;
if(arr[i] >0){
sum= sum+arr[i];
s2++;
}
}
if(sum==0){
System.out.print(s1+" "+"0.0"+"\n");
}else if(sum!=0){
System.out.print(s1+" "+String.format("%.1f",sum/s2)+"\n");
}
}
} import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int countFu = 0;
int countZh = 0;
double sum = 0.0;
for (int i = 0; i < n; i++) {
int in = sc.nextInt();
if (in < 0) {
countFu++;
}
if (in > 0) {
countZh++;
sum = sum + in;
}
}
System.out.println(countFu + " " + (countZh > 0? new DecimalFormat("######0.0").format(sum/countZh) : 0.0));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
//负数个数
int negCount = 0;
//正数之和
int pos = 0;
//正数个数
int posCount = 0;
for(int i = 0; i < n; i++){
int num = sc.nextInt();
if(num < 0){
negCount++;
}
if(num > 0){
pos += num;
posCount++;
}
}
System.out.printf("%d %.1f\n",negCount,(double)pos/posCount);
}
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int [] a = new int[n];
int c1 = 0;
int c2 = 0;
double sum = 0;
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
if(a[i] < 0){
c1 ++;
}
if(a[i] > 0){
c2 ++;
sum += a[i];
}
}
double average = sum / c2;
System.out.printf("%d %.1f\n", c1, average);
}
}
} import java.util.*;
public class Main{
public static void main(String []args){
Scanner scan=new Scanner(System.in);
while(scan.hasNext()){
int n=scan.nextInt();
int zheng=0,fu=0;
float sum=0;
while(n>0){
int x=scan.nextInt();
if(x<0){
fu++;
}else if(x>0){
sum+=x;
zheng++;
}
n--;
}
System.out.printf("%d %.1f\n",fu,sum/zheng);
}
}
}