Pagini recente » Cod sursa (job #1530747) | Cod sursa (job #270772) | Cod sursa (job #999050) | Cod sursa (job #907599) | Cod sursa (job #2000934)
#include <cstdio>
#include <algorithm>
#define BUF_SIZE 1 << 17
#define MAXN 500000
int v[MAXN];
FILE *fin = fopen("algsort.in", "r"), *fout = fopen("algsort.out", "w");
int pos = BUF_SIZE, poz = 0;
char buf[BUF_SIZE], buf2[BUF_SIZE], s[10];
inline char nextch() {
if (pos == BUF_SIZE) fread(buf, 1, BUF_SIZE, fin), pos = 0;
return buf[pos++];
}
inline int read(int &x) {
x = 0;
char ch = nextch();
while (!isdigit(ch)) ch = nextch();
while (isdigit(ch)) {
x = 10 * x + ch - '0';
ch = nextch();
}
return x;
}
inline void putch(char ch) {
buf2[poz++] = ch;
if (poz == BUF_SIZE) fwrite(buf2, 1, BUF_SIZE, fout), poz = 0;
}
inline void baga(int x) {
int k = 0;
do {
s[++k] = x % 10;
x /= 10;
} while(x);
for (; k; k--)
putch(s[k] + '0');
}
int main() {
int n;
read(n);
for (int i = 0; i < n; i++)
read(v[i]);
std::sort(v, v + n);
for (int i = 0; i < n; i++) {
baga(v[i]);
if (i < n - 1)
putch(' ');
}
putch('\n');
fwrite(buf2, 1, poz, fout);
fclose(fin);
fclose(fout);
return 0;
}