summaryrefslogtreecommitdiff
path: root/5.c
diff options
context:
space:
mode:
Diffstat (limited to '5.c')
-rw-r--r--5.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/5.c b/5.c
new file mode 100644
index 0000000..9ba87a5
--- /dev/null
+++ b/5.c
@@ -0,0 +1,87 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define MAX_BOARDS 100
+
+static char *ReadLine(char *p, size_t size, FILE *fp)
+{
+ if ((p=fgets(p, size, fp)))
+ {
+ size_t l = strlen(p);
+
+ while(l && p[l-1] == '\n')
+ {
+ p[--l] = 0;
+ }
+ }
+
+ return p;
+}
+
+static int Max(int a, int b)
+{
+ return a > b ? a : b;
+}
+
+static int Min(int a, int b)
+{
+ return a < b ? a : b;
+}
+
+int main(void)
+{
+ char buff[1024];
+ int board[1000][1000] = {0};
+ char *p = NULL;
+ int f = 0;
+ int x1 = 0;
+ int y1 = 0;
+ int x2 = 0;
+ int y2 = 0;
+ int x = 0;
+ int y = 0;
+ int sum = 0;
+
+ while (ReadLine(buff, sizeof buff, stdin))
+ {
+ p = strtok(buff, " ,->");
+ x1 = atoi(p);
+ p = strtok(NULL, " ,->");
+ y1 = atoi(p);
+ p = strtok(NULL, " ,->");
+ x2 = atoi(p);
+ p = strtok(NULL, " ,->");
+ y2 = atoi(p);
+
+ if (x1 == x2)
+ {
+ for(y = Min(y1, y2); y <= Max(y1, y2); y++)
+ {
+ board[y][x1]++;
+ }
+ }
+ else if (y1 == y2)
+ {
+ for(x = Min(x1, x2); x <= Max(x1, x2); x++)
+ {
+ board[y1][x]++;
+ }
+ }
+ }
+
+ for(y = 0; y < 999; y++)
+ {
+ for(x = 0; x < 999; x++)
+ {
+ if (board[y][x] > 1)
+ {
+ sum++;
+ }
+ }
+ }
+
+ printf("sum = %d\n", sum);
+
+ return 0;
+}