题解 | #记负均正#

记负均正

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        int sum=0;
        int lcount=0;
        int rcount=0;
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
            if (arr[i]<0){
                lcount++;
            }else if (arr[i]>=0){
                sum+=arr[i];
                if (arr[i]>0){
                    rcount++;
                }
            }
        }
        if (sum==0){
            System.out.println(lcount+" "+0.0f);
        }else {
            double f=sum*1.0/rcount;
            System.out.println(lcount+" "+String.format("%.1f",f));
        }




    }
}

全部评论

相关推荐

10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务