summaryrefslogtreecommitdiff
path: root/kattis-kth-alginda-quicksort/radix64.c
diff options
context:
space:
mode:
Diffstat (limited to 'kattis-kth-alginda-quicksort/radix64.c')
-rw-r--r--kattis-kth-alginda-quicksort/radix64.c31
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);