题解 | #记负均正#

记负均正

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

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;
        while ((str = bf.readLine()) != null) {
            str = bf.readLine();
            String[] s = str.split(" ");
            int[] temp = new int[s.length];
            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 + " " + "0.0");
            } else {
                double avg = (double) res / flag;
                DecimalFormat dateFormat = new DecimalFormat("#0.0");
                System.out.println(count + " " + dateFormat.format(avg));
            }


        }

    }




}

全部评论

相关推荐

点赞 评论 收藏
分享
一天代码十万三:实习东西太少了,而且体现不出你业务,3个月不可能就这点产出吧,建议实习多写点,玩具项目面试官都不感兴趣的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务