Question no.: 201612-1 Question name: Intermediate time limit: 1.0s memory limit: 256.0MB
The problem is described in an integer sequence a1, A2, ..., an, if there is a number, the number of integers greater than it equals the number of integers less than it is called an intermediate number. In a sequence, there may be multiple intermediate numbers with different subscripts, and the values of these intermediate numbers are the same.
Given an integer sequence, find the value of the middle number of this integer sequence. Input format the first line of input contains an integer n, which represents the number of integers in an integer sequence.
The second line contains n positive integers, which in turn indicate A1, A2, ..., an. Output format If the intermediate number of the contract sequence exists, the value of the intermediate number is output, otherwise the output-1 indicates that there is no intermediate number. Sample Input 6
2 6 5 6 3 5 Sample Output 5 example shows 5 smaller than 2, 5 larger than 2. Sample Input 4
3 4 6 7 Sample output-1 The example shows that the number of 4 in the sequence does not meet the definition of the middle number. Sample Input 5
3 4 6 6 7 Sample output-1 The example shows that the number of 5 in the sequence does not meet the definition of the intermediate number. Evaluate use case size and conventions for all evaluation cases, 1≤n≤1000,1≤ai≤1000.
#include <iostream>using namespacestd;intMain () {intn,i,j; inta[1001]; CIN>>N; intC; BOOLflag=false; for(i=0; i<n;i++) cin>>A[i]; for(i=0; i<n;i++){ intbig=0, small=0; for(j=0; j<n;j++){ if(A[i]>a[j]) big++; Else if(A[i]<a[j]) small++; } if(big==small) {Flag=true; C=A[i]; } } if(flag) cout<<C; Elsecout<<"-1"; return 0;}
201612-1 Middle Number