Cod sursa(job #2942862)

Utilizator proflaurianPanaete Adrian proflaurian Data 20 noiembrie 2022 11:07:00
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.87 kb
#include<bits/stdc++.h>
using namespace std;
const int N = 500010;
int n,v[N];
int poz;
char buff[30010];
void inc()
{
    poz++;
    if(poz==30000)
    {
        poz=0;fread(buff,1,30000,stdin);
    }
}
void read(int &x)
{
    while(buff[poz]<'0'||buff[poz]>'9')inc();
    x=0;
    while(buff[poz]>='0'&&buff[poz]<='9')
    {
        x=10*x+buff[poz]-'0';
        inc();
    }

}
class OutParser {
private:
    FILE *fout;
    char *buff;
    int sp;

    void write_ch(char ch) {
        if (sp == 50000) {
            fwrite(buff, 1, 50000, fout);
            sp = 0;
            buff[sp++] = ch;
        } else {
            buff[sp++] = ch;
        }
    }


public:
    OutParser(const char* name) {
        fout = fopen(name, "w");
        buff = new char[50000]();
        sp = 0;
    }
    ~OutParser() {
        fwrite(buff, 1, sp, fout);
        fclose(fout);
    }

    OutParser& operator << (int vu32) {
        if (vu32 <= 9) {
            write_ch(vu32 + '0');
        } else {
            (*this) << (vu32 / 10);
            write_ch(vu32 % 10 + '0');
        }
        return *this;
    }

    OutParser& operator << (long long vu64) {
        if (vu64 <= 9) {
            write_ch(vu64 + '0');
        } else {
            (*this) << (vu64 / 10);
            write_ch(vu64 % 10 + '0');
        }
        return *this;
    }

    OutParser& operator << (char ch) {
        write_ch(ch);
        return *this;
    }
    OutParser& operator << (const char *ch) {
        while (*ch) {
            write_ch(*ch);
            ++ch;
        }
        return *this;
    }
};
OutParser fout("algsort.out");
int main ()
{
    freopen("algsort.in","r",stdin);
    read(n);
    for(int i=1;i<=n;i++)
        read(v[i]);
    sort(v+1,v+n+1);
    for(int i=1;i<=n;i++)
        fout<<v[i]<<' ';
    return 0;
}