Cod sursa(job #2022829)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 17 septembrie 2017 14:28:57
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include <cstdio>
#include <cctype>
#include <algorithm>

#define BUF_SIZE 1 << 17

#define MAXN 500000

int v[MAXN];

int pos = BUF_SIZE, poz = 0;
char buf[BUF_SIZE], fub[BUF_SIZE], c[11];
FILE *fin = fopen("algsort.in", "r"), *fout = fopen("algsort.out", "w");

inline char nextch() {
    if (pos == BUF_SIZE) fread(buf, 1, BUF_SIZE, fin), pos = 0;
    return buf[pos++];
}

inline int read() {
    char ch;
    while (!isdigit(ch = nextch()));
    int x = ch - '0';
    while (isdigit(ch = nextch())) x = 10 * x + ch - '0';
    return x;
}

inline void putch(char ch) {
    fub[poz++] = ch;
    if (poz == BUF_SIZE) fwrite(fub, 1, BUF_SIZE, fout), poz = 0;
}

inline void write(int x) {
    int s = 0;
    do { c[++s] = x % 10 + '0'; } while ((x /= 10) > 0);
    for (; s; s--) putch(c[s]);
}

int main() {
    int n = read();
    for (int i = 0; i < n; i++)
        v[i] = read();

    std::sort(v, v + n);

    for (int i = 0; i < n; i++) {
        write(v[i]);
        if (i < n - 1) putch(' ');
        else putch('\n');
    }

    fwrite(fub, 1, poz, fout);

    fclose(fin);
    fclose(fout);
    return 0;
}