Cod sursa(job #1316655)

Utilizator thinkphpAdrian Statescu thinkphp Data 13 ianuarie 2015 23:17:04
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
/**
 *  @author      Adrian Statescu <[email protected]>
 *  @description std::sort the elements in the range [first, last) in Action. 
 *  @License     MIT 
 */
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define FIN "algsort.in"
#define FOUT "algsort.out"
#define MAXN 500005

int  vec[ MAXN ],
     N;
char str[ 5500000 ];

int main() {

    freopen(FIN, "r", stdin);

    scanf("%d\n", &N);

    gets(str);

    fclose( stdin );

    str[ strlen( str ) ] = ' ';

    int j = 0;  

    for(int i = 0; i < N; ++i) {

        int num = 0;

        while(str[ j ] != ' ') {
          
              num = num * 10 + str[ j++ ] - '0';
        } 

        j++;

        vec[ i ] = num; 
    } 

    std::sort(vec,vec + N);  

    freopen(FOUT, "w", stdout);

    for(int i = 0; i < N; ++i) printf("%d ", vec[ i ]);
    fclose( stdout );
   
    return(0); 
};