-
Notifications
You must be signed in to change notification settings - Fork 9
/
bits.c
75 lines (57 loc) · 1.3 KB
/
bits.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include <math.h>
const int w = 96;
int main() {
char line[128];
short val;
int hi = 0;
int lo = 0;
int i = 0;
int n = 0;
int j = 0;
int v;
for (;;) {
fgets(line, sizeof(line) - 1, stdin);
if (feof(stdin))
break;
sscanf(line, "%hd ", &val);
if (val < 6 || val > 9) {
lo = hi = n = 0;
continue;
}
if (lo) {
if (val <= 7) {
n++;
} else {
v = (int)rint(n / 6.0);
for (i = 0; i < v; i++) {
putchar('0');
if (++j % w == 0)
putchar('\n');
}
n = 1;
lo = 0;
hi = 1;
}
} else {
if (val >= 8) {
n++;
} else {
v = (int)rint(n / 5.0);
for (i = 0; i < v; i++) {
putchar('1');
if (++j % w == 0)
putchar('\n');
}
n = 1;
lo = 1;
hi = 0;
}
}
}
exit(EXIT_SUCCESS);
}