blob: 3e60177c6c2e703a0706d58dff47d3814c56f5e7 (
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
55
56
|
#include <stdio.h>
#include <stdlib.h>
static int h, w;
static int paper[2048][2048];
static void foldY(int fold) {
for (int y = 0; y < fold; ++y)
for (int x = 0; x < w; ++x) {
paper[y][x] |= paper[h-1-y][x];
}
h = fold;
}
static void foldX(int fold) {
for (int x = 0; x < fold; ++x)
for (int y = 0; y < h; ++y) {
paper[y][x] |= paper[y][w-1-x];
}
w = fold;
}
static int sum(void) {
int sum = 0;
for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x) {
sum += paper[y][x];
}
return sum;
}
int main(void) {
int x, y;
while (2 == scanf("%d,%d\n", &x, &y)) {
paper[y][x] = 1;
if (y >= h) h = y+1;
if (x >= w) w = x+1;
}
char axis;
int fold;
int first = 1;
while (EOF != scanf(" fold along %c=%d\n", &axis, &fold)) {
if (axis == 'y') {
foldY(fold);
} else if (axis == 'x') {
foldX(fold);
} else {
printf("??? %c\n", axis);
}
if (first) {
printf("%d\n", sum());
first = 0;
}
}
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
printf("%c", (paper[y][x] ? '#' : '.'));
}
printf("\n");
}
}
|