/******************************************************************** @file Main_practise.cpp @date 2014-8-22 @author Tiger @brief What is the Median? ********************************************************************/ #include <cstdio> #include <vector> #include <algorithm> //#define OJ void 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; }
UVA-10107
时间: 2024-11-12 13:34:27