题解 | #记负均正#

记负均正

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));
            }


        }

    }




}

全部评论

相关推荐

06-25 21:00
门头沟学院 Java
多拆解背记一下当前的高频场景面试题,结合自己的项目经历去作答,面试通过率原来真的不会低!
牛客96559368...:小公司不就是这样的吗,面试要么是点击就送,要么就是往死里拷打,没有一个统一的标准。这个不能代表所有公司
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-27 20:55
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务