Cod sursa(job #2242605)

Utilizator proflaurianPanaete Adrian proflaurian Data 18 septembrie 2018 23:59:51
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 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);
    string nrToString(int x){stringstream aux;string s;aux<<x;aux>>s;s=s+' ';return s;}
};
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)
        result = result + nrToString(it);
    printf("%s",result.c_str());
    return *this;
}