您的位置:首页 > 其它

POJ 2388 && HDU 1157 Who's in the Middle(水~)

2015-08-27 09:42 549 查看
Description

给定n(n为奇数)个数,输出其中位数

Input

第一行为n,之后n行每行一个数(1<=n<=10000)

Output

输出这n个数的中位数

Sample Input

5

2

4

1

3

5

Sample Output

3

Solution

纯净水…

Code

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 10001
int num[maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
sort(num,num+n);
printf("%d\n",num[n/2]);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: