2. Delete the largest and smallest

Title description

Please write a program, input n different integers, delete the largest number and the smallest number, and output the remaining n-2 integers in turn.

Input and output format

Input format

There are two lines of input: the first line is a positive integer n, and the second line is n integers.
Where n<=100, the absolute value of the number does not exceed 100000.

Output format

There are n-2 integers in a row

Sample input and output

Input sample

5
10 8 5 2 6

Sample output

8 5 6

answer

Water question~
Core idea: Record the maximum value MAX and the minimum value MIN, and judge at the last cycle, and then output them in turn.
Let's code~

Code

#include<bits/stdc++.h>
using namespace std;
const int N=109,INF=1e9;
int n,MAX=-INF,MIN=INF,f[N];
int main() {
    
    
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&f[i]),MAX=max(MAX,f[i]),MIN=min(MIN,f[i]);
    for(int i=1;i<=n;i++)if(f[i]!=MAX&&f[i]!=MIN)printf("%d ",f[i]);
    return 0;
}

Guess you like

Origin blog.csdn.net/JPY_Ponny/article/details/114155347