Wednesday, February 9, 2011

10107 - What is the Median?


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<conio.h>
using namespace std;
int main()
{
    unsigned long long x[10050],med;
    long i=0,n;
    //freopen("in.txt","r",stdin);
    while(scanf("%llu",&x[i++])==1)
    {
        sort(x,x+i);
        n=i>>1;
        if(i&1)
            med=x[n];
        else
            med=x[n-1]+x[n],med=med>>1;
        printf("%llu\n",med);
    }
    exit(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.