首页 > 代码库 > UVA-10107

UVA-10107

/********************************************************************@file     Main_practise.cpp@date     2014-8-22@author   Tiger@brief    What is the Median?********************************************************************/#include <cstdio>#include <vector>#include <algorithm>//#define OJvoid Insert(std::vector<int>& vec, int nNum);int main(int argc, const char* argv[]){#ifdef OJ    freopen("input.txt", "r", stdin);#endif    std::vector<int> vec;    int nNum = 0;    while (scanf("%d", &nNum) != EOF)    {        vec.push_back(nNum);        sort(vec.begin(), vec.end());        int nPos = vec.size()/2;        if ((vec.size() & 1) == 1)        {            printf("%d\n", vec.at(nPos));        }        else        {            printf("%d\n", (vec.at(nPos-1)+vec.at(nPos))/2);        }    }    return 0;}