AnonymousNamefag

Advent of Code Day 3 Part 1

Dec 11th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. // This program is a filter.
  2. // Input file should be fed
  3. // into standard input.
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. int fabric[1000][1000];
  10.  
  11. int main( int argc, char **argv ){
  12.     int c;
  13.     int x, y, w, h;
  14.     char buf[40];
  15.     while( (c = fgetc( stdin )) != EOF ){
  16.         fgets( buf, 40, stdin );
  17.         strtok( buf, " " );
  18.         strtok( NULL, " " );
  19.         x = atoi( strtok( NULL, "," ) );
  20.         y = atoi( strtok( NULL, ": " ) );
  21.         w = atoi( strtok( NULL, "x" ) );
  22.         h = atoi( strtok( NULL, "\n" ) );
  23.         for( int i = x; i < x + w; i++ ){
  24.             for( int j = y; j < y + h; j++ ){
  25.                 fabric[i][j]++;
  26.             }
  27.         }
  28.     }
  29.     int overlap = 0;
  30.     for( int i = 0; i < 1000; i++ ){
  31.         for( int j = 0; j < 1000; j++ ){
  32.             if( fabric[i][j] >= 2 ) overlap++;
  33.         }
  34.     }
  35.     printf( "%d\n", overlap );
  36.     return 0;
  37. }
Add Comment
Please, Sign In to add comment