B2097 The Longest Platform 【Getting Started】

White blood cell count

topic description

The hospital samples the number of white blood cells during the treatment of a clinical case nnn copies are used to analyze the therapeutic effect of a new antibiotic on the case. In order to reduce the analysis error, it is necessary to start from thisnnRemove a sample with the largest value and a sample with the smallest value from n samples, and then divide the remaining n − 2 n-2nThe average of 2 effective samples was used as the analysis index. At the same time, in order to observe whether the curative effect of the antibiotic is stable, the error of the average value is also given, that is, the maximum value of the absolute value of the difference between all valid samples (that is, excluding the two samples that have been deducted) and the average value.

Now please write a program, according to the provided nnFor n sample values, calculate the average number of white blood cells and the corresponding error of the case.

input format

The first line of input is a positive integer nnn 2 < n ≤ 300 2<n \le 300 2<n300 ), indicating a total ofnnn samples.

There are nn belown lines, each line is a floating-point number, which is the corresponding number of white blood cells, and its unit is1 0 9 / L 10^9/L109 /L. Numbers are separated by a space.

output format

The output is two floating-point numbers separated by a space. They are the average white blood cell count and the corresponding error, and the unit is also 1 0 9 / L 10^9/L109 /L. Calculation results need to be kept to22 digits.

Example #1

Sample Input #1

5
12.0
13.0
11.0
9.0
10.0

Sample output #1

11.00 1.00

Simply put, it is to find the longest continuous string in an array

import java.io.*;
import java.sql.SQLSyntaxErrorException;
import java.util.*;
import java.util.List;
import java.security.cert.PolicyNode;
import java.util.Scanner;//输入头文件
import java.util.Arrays;//引入数组类

public class Main {
    
    
    public static void main(String[] args) {
    
    
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int [n+1];
        a[0]=-2;//将a[0]作为一个标志
        int len=1,res=0;
        for(int i=1;i<=n;++i){
    
    
            a[i]=in.nextInt();
            if(a[i]==a[i-1])//如果输入的值和前一个值相等就加一
                ++len;
            else//不相等说明前面连续的字串断开,要重新计数
                len=1;
            res=Math.max(res,len);//每一次都记录一下最大值
        }
        System.out.println(res);
    }
}


Guess you like

Origin blog.csdn.net/xiatutut/article/details/129640936