题解 | #记负均正#

记负均正

http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

import java.util.*;

public class Main{

public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()){
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = sc.nextInt();
        }
        int count1 = 0, sum = 0, count2 = 0, count0 = 0;
        
        for(int i = 0; i < n; i++){
            if(arr[i] < 0) count1++;
            if(arr[i] > 0){
                sum += arr[i];
                count2++;
            }
            if(arr[i] == 0){
                count0++;
            }
        }
        if(count0 == arr.length){
            System.out.println(count1 + " " + "0.0");
        }else{
            System.out.println(count1 + " " + String.format("%.1f", sum * 1.0 / count2) + "\n");
        }
    }
}

}

全部评论

相关推荐

10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务