diff options
author | mathiasmagnusson <mathiasmagnussons@gmail.com> | 2022-02-28 19:10:54 +0100 |
---|---|---|
committer | mathiasmagnusson <mathiasmagnussons@gmail.com> | 2022-02-28 19:10:54 +0100 |
commit | d76ab9f13f60e9ca8a0e578d9cb209064a9a790d (patch) | |
tree | 9be7b73fd162d9668f56993f798768a339714450 /kattis-kth-alginda-quicksort/radix64.c | |
parent | d5473756b304ebda9eeee6592e4555d15c910ee2 (diff) | |
download | programming-problem-solving-d76ab9f13f60e9ca8a0e578d9cb209064a9a790d.tar.gz |
Minor input format degeneralization
Diffstat (limited to 'kattis-kth-alginda-quicksort/radix64.c')
-rw-r--r-- | kattis-kth-alginda-quicksort/radix64.c | 31 |
1 files changed, 13 insertions, 18 deletions
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); |