blob: 93d6dfd3a123e92f92f0f92e177bfd51ec3031a0 (
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
|
#include <stdio.h>
#include <stdlib.h>
static int sign(int x) {
return (x > 0 ? 1 : x < 0 ? -1 : 0);
}
int main(void) {
static int grid[1024][1024];
static int grid2[1024][1024];
int x1, y1, x2, y2;
while (4 == scanf("%d,%d -> %d,%d\n", &x1, &y1, &x2, &y2)) {
int dx = sign(x2 - x1);
int dy = sign(y2 - y1);
for (
int y = y1, x = x1;
(dy > 0 ? y <= y2 : y >= y2) && (dx > 0 ? x <= x2 : x >= x2);
x += dx, y += dy
) {
if (x1 == x2 || y1 == y2) grid[y][x]++;
grid2[y][x]++;
}
}
int points = 0;
for (int y = 0; y < 1024; ++y)
for (int x = 0; x < 1024; ++x) {
if (grid[y][x] > 1) points++;
}
printf("%d\n", points);
points = 0;
for (int y = 0; y < 1024; ++y)
for (int x = 0; x < 1024; ++x) {
if (grid2[y][x] > 1) points++;
}
printf("%d\n", points);
}
|