Cod sursa(job #692780)

Utilizator laurionLaurentiu Ion laurion Data 26 februarie 2012 19:26:53
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
// problema sortare, arhiva educationala, varianta C++
# include <algorithm>
# include <fstream>
using namespace std;

# define verf ++poz == hg ? f.read (ch, hg), poz = 0 : 0

const char *FIN = "algsort.in", *FOU = "algsort.out";
const int MAX = 500001, hg = 1 << 13;

ifstream f (FIN);
ofstream g (FOU);

int N, poz, A[MAX];
char ch[hg];

inline void cit ( int &x ) {
    if (ch[0] == '\0') f.read (ch, hg) ;
    else for (; ch[poz] < '0' || ch[poz] > '9' ; verf) ;
    for (x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf) ;
}

int main (void) {
    cit (N);
    for (int i = 0; i < N; ++i)
        cit (A[i]);
    sort (A, A + N);
    for (int i = 0; i < N; ++i)
        g << A[i] << " ";
}