1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdio.h> #include <stdlib.h> #include <string.h> int compare(const void* a1, const void* a2) { const char** s1 = a1; const char** s2 = a2; const int result = strcmp(*s1, *s2); return result; } int main() { char* s[] = { "e", "d", "c", "b", "a" }; const size_t s_element_size = sizeof(s[0]); const size_t s_element_count = sizeof(s) / s_element_size; size_t i; for (i = 0; i < s_element_count; i++) { printf("[%s]\n", s[i]); } printf("\n"); qsort(s, s_element_count, s_element_size, compare); for (i = 0; i < s_element_count; i++) { printf("[%s]\n", s[i]); } return 0; } |
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50IGNvbXBhcmUoY29uc3Qgdm9pZCogYTEsIGNvbnN0IHZvaWQqIGEyKQp7CiAgICBjb25zdCBjaGFyKiogczEgICA9IGExOwogICAgY29uc3QgY2hhcioqIHMyICAgPSBhMjsKICAgIGNvbnN0IGludCByZXN1bHQgPSBzdHJjbXAoKnMxLCAqczIpOyAKICAgIHJldHVybiByZXN1bHQ7Cn0KCmludCBtYWluKCkKewogICAgY2hhciogc1tdID0geyAiZSIsICJkIiwgImMiLCAiYiIsICJhIiB9OwogICAgY29uc3Qgc2l6ZV90IHNfZWxlbWVudF9zaXplICA9IHNpemVvZihzWzBdKTsKICAgIGNvbnN0IHNpemVfdCBzX2VsZW1lbnRfY291bnQgPSBzaXplb2YocykgLyBzX2VsZW1lbnRfc2l6ZTsKICAgIHNpemVfdCBpOwoKICAgIGZvciAoaSA9IDA7IGkgPCBzX2VsZW1lbnRfY291bnQ7IGkrKykKICAgIHsKICAgICAgICBwcmludGYoIlslc11cbiIsIHNbaV0pOwogICAgfQogICAgcHJpbnRmKCJcbiIpOwoKICAgIHFzb3J0KHMsIHNfZWxlbWVudF9jb3VudCwgc19lbGVtZW50X3NpemUsIGNvbXBhcmUpOwoKICAgIGZvciAoaSA9IDA7IGkgPCBzX2VsZW1lbnRfY291bnQ7IGkrKykKICAgIHsKICAgICAgICBwcmludGYoIlslc11cbiIsIHNbaV0pOwogICAgfQoKICAgIHJldHVybiAwOwp9Cg==
-
upload with new input
-
result: Success time: 0.01s memory: 1676 kB returned value: 0
[e] [d] [c] [b] [a] [a] [b] [c] [d] [e]


