Cod sursa(job #775876)

Utilizator costyrazvyTudor Costin Razvan costyrazvy Data 9 august 2012 11:29:29
Problema Sortare prin comparare Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define pb push_back
using namespace std;
vector <int> h[10] ;
int a[500001],i,mx,y,p,j,n;
int main()
{
    ifstream f("algsort.in");
    ofstream g("algsort.out");
    f>>n;
    for (i=1;i<=n;i++) f>>a[i];
    for  ( i=1; i<=n; i++ )
       mx=max(mx,a[i]);

    p=mx; y=1;
    while (p>=y) {
      for (i=0;i<10;i++) h[i].clear();
     for (i=1;i<=n;i++)
            h[(a[i]/y%10)%666013].pb(a[i]);
     y*=10;
     n=0;
     for (i=0;i<10; i++)
        for(j=0; j<h[i].size();j++)
          a[++n]= h[i][j];
    }

    for (i=1; i<=n; i++) g<<a[i]<<" ";
    f.close();
    g.close();
    return 0;
}