Sunday, July 24, 2016

UVA 541 - Error Correction

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0)
using namespace std;
int main()
{
    FAST;
    vector<int>v;
    int x;
    while(cin>>x){
        v.push_back(x);
        sort(v.begin(),v.end());
        if(v.size()%2==0) cout<<(v[(v.size()+1)/2-1]+v[(v.size()+1)/2])/2<<'\n';
        else cout<<v[(v.size()+1)/2-1]<<'\n';
    }
    return 0;
}

No comments:

Post a Comment