From d76ab9f13f60e9ca8a0e578d9cb209064a9a790d Mon Sep 17 00:00:00 2001 From: mathiasmagnusson Date: Mon, 28 Feb 2022 19:10:54 +0100 Subject: Minor input format degeneralization --- kattis-kth-alginda-quicksort/radix64.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'kattis-kth-alginda-quicksort/radix64.c') diff --git a/kattis-kth-alginda-quicksort/radix64.c b/kattis-kth-alginda-quicksort/radix64.c index 4113a94..54b0155 100644 --- a/kattis-kth-alginda-quicksort/radix64.c +++ b/kattis-kth-alginda-quicksort/radix64.c @@ -18,7 +18,7 @@ void radix_sort(int n) { long *in = tmp; // we loop an even amount of times so the completely sorted array // will be in xs, not tmp - for (int m = 0; m < 44; m += 8) { + for (int m = 0; m < 40; m += 8) { long *tmp = out; out = in; in = tmp; @@ -39,12 +39,13 @@ void radix_sort(int n) { } } } + int main() { ssize_t len = read(0, buffer, BUFFER_MAX); char *p = buffer; int n = 0; - while (*p != ' ' && *p != '\n') { + while (*p != ' ') { n *= 10; n += *p - '0'; p++; @@ -57,20 +58,17 @@ int main() { long x = 0; bool c = true; - if (c) x += (long)(*p-- - '0') << 0; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 4; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 8; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 12; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 16; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 20; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 24; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 28; if (*p == ' ' || *p == '-') c = false; - if (c) x += (long)(*p-- - '0') << 32; if (*p == ' ' || *p == '-') c = false; + if (c) x += (long)(*p-- - '0') << 0; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 4; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 8; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 12; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 16; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 20; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 24; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 28; if (*p == ' ' || *p == '\n') c = false; + if (c) x += (long)(*p-- - '0') << 32; if (*p == ' ' || *p == '\n') c = false; if (c) x += (long)(*p-- - '0') << 36; - if (*p == '-') p--; - else x |= 1l << 40; - xs[i] = x; } @@ -81,9 +79,7 @@ int main() { *p-- = '\n'; for (int i = n - 1; i >= 0; i--) { long x = xs[i]; - bool neg = x >> 40 == 0; - x &= ~(1l << 40); - *p-- = (x & 0xf) + '0'; x >>= 4; + *p-- = (x & 0xf) + '0'; x >>= 4; if (x) *p-- = (x & 0xf) + '0'; x >>= 4; if (x) *p-- = (x & 0xf) + '0'; x >>= 4; if (x) *p-- = (x & 0xf) + '0'; x >>= 4; @@ -93,7 +89,6 @@ int main() { if (x) *p-- = (x & 0xf) + '0'; x >>= 4; if (x) *p-- = (x & 0xf) + '0'; x >>= 4; if (x) *p-- = (x & 0xf) + '0'; x >>= 4; - if (neg) *p-- = '-'; if (i > 0) *p-- = '\n'; } write(1, p + 1, last - p); -- cgit v1.2.3