Cod sursa(job #3232802)

Utilizator popescu_georgePopescu George popescu_george Data 1 iunie 2024 14:02:32
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("algsort.in");
ofstream G("algsort.out");
#define Z 2048
int n,i,a[500000],p=Z,q,j,k,b[10];
char s[Z],t[Z];
inline char A()
{
    if(p==Z)
        F.read(s,Z),p=0;
    return s[p++];
}
int B()
{
    char c;
    int n=0;
    for(c=A();isdigit(c);n=n*10+c-48,c=A());
    return n;
}
inline void C()
{
    if(q==Z)
        G.write(t,Z),q=0;
}
int main()
{
    for(n=B();i<n;a[i++]=B());
    for(sort(a,a+n),i=0;i<n;t[q++]=' ',C(),++i) {
        for(j=0,k=a[i],b[j++]=k%10,k/=10;k;b[j++]=k%10,k/=10);
        for(;j;t[q++]=b[--j]+48,C());
    }
    return G.write(t,q),0;
}