about summary refs log tree commit diff
path: root/usth/ICT3.4/a51.c
blob: 7925f0204beefc9e6b2b9295c9226f12222ebe70 (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}