Advertisement
quetzelcoatlus

10.c

Dec 10th, 2022 (edited)
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int sum=0;
  6.  
  7. int checks[] = {20,60,100,140,180,220};
  8.  
  9. void check(int cycle, int r){
  10.     for(unsigned int k=0;k<sizeof(checks)/sizeof(checks[0]);k++)
  11.         if(cycle == checks[k])
  12.             sum+=cycle*r;
  13. }
  14.  
  15. void main(){
  16.     char op[10];
  17.     int d=0;
  18.  
  19.     int cycle=1,regx=1;
  20.     while(scanf("%s %d\n",op,&d) > 0){
  21.         check(cycle,regx);
  22.         if(!strcmp("noop",op)){
  23.             cycle++;
  24.         } else {
  25.             check(++cycle,regx);
  26.             regx+=d;
  27.             cycle++;
  28.         }
  29.     }
  30.  
  31.     printf("%d\n", sum);
  32. }
Tags: adventofcode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement