- int i = 0;
- char buf[1000];
- while (fgets(buf, 1000, stdin) != NULL) {
- char *p = &buf[0];
- lines[i].x1 = strtol(p, &p, 10);
- p++;
- lines[i].y1 = strtol(p, &p, 10);
- p+=4;
- lines[i].x2 = strtol(p, &p, 10);
- p++;
- lines[i].y2 = strtol(p, &p, 10);
- if (lines[i].x1 == lines[i].x2)
- lines[i].d = vert;
- else if (lines[i].y1 == lines[i].y2)
- lines[i].d = horz;
- else
- continue;
- *maxx = max(*maxx, lines[i].x1);
- *maxx = max(*maxx, lines[i].x2);
- *maxy = max(*maxy, lines[i].y1);
- *maxy = max(*maxy, lines[i].y2);
- i++;
+ struct entry *p;
+ struct point s;
+ memset(&s, 0, sizeof s);
+ s.x = x;
+ s.y = y;
+ HASH_FIND(hh, *entries, &s, sizeof(struct point), p);
+ if (p) {
+ if (p->i++ == 1)
+ *r = *r+1;
+ } else {
+ p = calloc(1, sizeof(struct entry));
+ p->key = s;
+ p->i = 1;
+ HASH_ADD(hh, *entries, key, sizeof(struct point), p);