Given an odd number of cows N (1 <= N < 10,000) and their milk output (1..1,000,000), find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
* Line 1: A single integer N <br> <br>* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
* Line 1: A single integer that is the median milk output.
样例输入
5
2
4
1
3
5
样例输出
3
题和代码都很简单
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int num,i;
int arr[10050];
while(cin>>num)
{
for(i=0;i<num;i++)
cin>>arr[i];
sort(arr,arr+num,cmp);
cout<<arr[(num-1)/2]<<endl;
}
return 0;
}