pz12_gavrilov

This is a task for our favourite professor
git clone git://git.stellar-nexus.ru/pz12_gavrilov
Log | Files | Refs

sort_single.c (1042B)


      1 #include <ctype.h>
      2 #include <limits.h>
      3 #include <stdio.h>
      4 #include <time.h>
      5 
      6 #include "sort.h"
      7 #include "util.h"
      8 
      9 #ifdef bubble
     10 #define sort bubble_sort
     11 #elif defined(choice)
     12 #define sort choice_sort
     13 #elif defined(insert)
     14 #define sort insert_sort
     15 #elif defined(shell)
     16 #define sort shell_sort
     17 #else
     18 #error You need to define either bubble, choice, insert, or shell
     19 #endif
     20 
     21 static long long int
     22 input(long long minval, long long maxval)
     23 {
     24 	unsigned char len = 0, arr[UCHAR_MAX];
     25 
     26 	for (int c = getchar(); !isspace(c) && c != EOF; c = getchar())
     27 		arr[len++] = c;
     28 	arr[len] = '\0';
     29 	return estrtonum(arr, minval, maxval);
     30 
     31 }
     32 
     33 int
     34 main(int argc, char *argv[])
     35 {
     36 	argv0 = argv[0];
     37 	unsigned int n = input(2, UINT_MAX);
     38 	int *arr = emalloc(sizeof(*arr) * n);
     39 	
     40 	unsigned int len;
     41 	for (len = 0; len < n; ++len)
     42 		arr[len] = input(INT_MIN, INT_MAX);
     43 	
     44 	clock_t solve_time = clock();
     45 	sort(n, arr);
     46 	solve_time = clock() - solve_time;
     47 	printf("%f\n", (double)solve_time / CLOCKS_PER_SEC);
     48 	for (len = 0; len < n; ++len)
     49 		printf("%d\n", arr[len]);
     50 }