#include #include #include using namespace std; int stonecompare( const void* , const void* ); int main() { int N; FILE* fi; FILE* fo; int* stones; int* trivpos; int i; int j = 0; int k = 0; int trivsum; int normsum; int thisstone; fi = fopen( "acropolis.in" , "r" ); fscanf( fi , "%i\n" , &N ); stones = ( int* )malloc( N * sizeof( int ) ); trivpos = ( int* )malloc( ( N + 1 ) * sizeof( int ) ); for( i = 0 ; i < N ; i++ ) { fscanf( fi , "%i\n" , &thisstone ); if( thisstone == 1 ) { trivpos[ k ] = i; k++; } else { stones[ j ] = thisstone; j++; } } fclose( fi ); trivpos[ k ] = -1; trivsum = k; normsum = j; qsort( stones , normsum , sizeof( int ) , stonecompare ); fo = fopen( "acropolis.out" , "w" ); i = j = k = 0; for( i = 0 ; i < N ; i++ ) if( trivpos[ k ] == i ) { fprintf( fo , "1\n" ); k++; } else { fprintf( fo , "%i\n" , stones[ j ] ); j++; } fclose( fo ); } int stonecompare( const void* one , const void* two ) { int i1; int i2; i1 = *(( int* )one); i2 = *(( int* )two); if( i1 > i2 ) return 1; else return -1; }