#include #include #include typedef struct Sortable { int value; char *sortable; char *printable; } Sortable; int comp(const void *a, const void *b){ Sortable *s_a = (Sortable*) a, *s_b = (Sortable*) b; return strcmp(s_b->sortable, s_a->sortable); } int main(int argc, char **argv){ size_t c = argc - 1; int i, l, max = 0; char *a, *b; Sortable *list = calloc(c, sizeof(struct Sortable)), *s; // Get the list of integers that the user has surely provided on the command line. for(s = list, i = 1; i <= c; s++, i++){ a = argv[i]; *s = (Sortable){ .value = atoi(a), .printable = a }; if((l = strlen(a)) > max) max = l; } // Build a sortable representation of the values by padding the end of numbers which are less than max length with their most significant digit. for(s = list, i = 1; i <= c; s++, i++){ b = s->sortable = calloc(max + 1, sizeof(char)); l = strlen(a = argv[i]); strncat(b, a, l); while(l++ < max) b[l - 1] = *b; b[max] = 0; } qsort(list, c, sizeof(struct Sortable), comp); // Output the largest number possible with these digits! for(i = 0; i < c; i++) fputs(list[i].printable, stdout); fputc('\n', stdout); return 0; }