diff options
Diffstat (limited to 'usth/ICT3.4/a51.c')
-rw-r--r-- | usth/ICT3.4/a51.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/usth/ICT3.4/a51.c b/usth/ICT3.4/a51.c new file mode 100644 index 0000000..7925f02 --- /dev/null +++ b/usth/ICT3.4/a51.c @@ -0,0 +1,54 @@ +#include <stdio.h> + +#define READ(t, n) for (int i = 0; i < n; ++i) t = t << 1 | (getchar() ^ 48) +#define POW2(t) (1 << (t)) + +#define MAXX POW2(18) +#define MAXY POW2(21) +#define MAXZ POW2(22) + +#define CLOCKX(x) ((x) & POW2(10)) +#define CLOCKY(y) ((y) & POW2(11)) +#define CLOCKZ(z) ((z) & POW2(12)) + +#define BIT(n, t) (((t) & POW2(n)) != 0) + +#define TAPX(x) ((BIT(0, x) ^ BIT(1, x) ^ BIT(2, x) ^ BIT(5, x)) << 18) +#define TAPY(y) ((BIT(0, y) ^ BIT(1, y)) << 21) +#define TAPZ(z) ((BIT(0, z) ^ BIT(1, z) ^ BIT(2, z) ^ BIT(15, z)) << 22) + +int main() +{ + int x = 0, y = 0, z = 0; + READ(x, 19); + getchar(); /* assume one-char sep */ + READ(y, 22); + getchar(); /* assume one-char sep */ + READ(z, 23); + + int n; + scanf("%d", &n); + while (n--) { + int minor = !CLOCKX(x) + !CLOCKY(y) + !CLOCKZ(z) > 1; + putchar(((x ^ y ^ z) & 1) + '0'); + + if (minor == !CLOCKX(x)) { + x >>= 1; + x &= ~MAXX; + x |= TAPX(x); + } + if (minor == !CLOCKY(y)) { + y >>= 1; + y &= ~MAXY; + y |= TAPY(y); + } + if (minor == !CLOCKZ(z)) { + z >>= 1; + z &= z & ~MAXZ; + z |= TAPZ(z); + } + } + + putchar(10); + return 0; +} |