Cod sursa(job #2243482)

Utilizator andrei42Oandrei42O andrei42O Data 20 septembrie 2018 18:01:07
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <bits/stdc++.h>

using namespace std;
const int b = 32000;
struct parser
{
    char *B,*E,*p;
    parser()
    {
        freopen("algsort.in","r",stdin);
        freopen("algsort.out","w",stdout);
        B = new char [ b + 10 ];
        E = B + b;
        LoadBuffer();

    }
    parser &operator>>(int &x)
    {
        while( *p < '0' || '9' < *p)if(++p==E)LoadBuffer();
        x=0;
        while( '0' <= *p && *p <= '9')
        {
            x = 10*x + *p - '0';
            if(++p==E)LoadBuffer();
        }
        return *this;
    }
    void operator>>(vector<int> &a)
    {
        int n,x;
        *this >> n;
        for(;n;n--)
        {
            *this >> x;
            a.push_back(x);
        }
        sort(a.begin(),a.end());
    }
    void operator<<(vector<int> a)
    {
        for(auto it:a)
            printf("%d ",it);
    }
    void LoadBuffer()
    {
        p=B;
        memset(B,0,b);
        fread(B,1,b,stdin);
    }
};
vector<int> v;
int main()
{
    parser f;
    f>>v;
    f<<v;
    return 0;
}