Cod sursa(job #2242608)

Utilizator proflaurianPanaete Adrian proflaurian Data 19 septembrie 2018 00:03:46
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
const size_t b = 1<<20;
const string problem="algsort";
struct R
{
    R();
    R& operator>>(int &);
    R& operator>>(vector<int>&v);
    char *B,*E,*p;
    void L();
};
struct W
{
    W();
    W operator<<(vector<int>v);
};
int n,x[N];
vector<int> V;
int main()
{
    R r;r>>V;
    W w;w<<V;
    return 0;
}
R::R(){freopen((problem+".in").c_str(),"r",stdin);B=new char[b+10];E=B+b;L();}
R& R::operator>>(int &x){while (*p<'0'||*p>'9') if(++p==E)L();x=0;while('0'<=*p&&*p<='9'){x=10*x+*p-'0';if(++p==E)L();}return *this;}
void R::L(){memset(B,0,b);fread(B,1,b,stdin);p=B;}
R& R::operator>>(vector<int>&v){int n,x;*this >> n;for(; n; n--){*this >> x;v.push_back(x);}sort(v.begin(),v.end());return *this;}
W::W(){freopen((problem+".out").c_str(),"w",stdout);}
W W::operator<<(vector<int> v)
{
    string result;
    for(auto it:v)
        printf("%d ",it);
    return *this;
}