main.c (638B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 char *line = NULL; 7 size_t len; 8 int ops = 1; 9 int x = 1; 10 11 int signal = 0; 12 13 while (getline(&line, &len, stdin) != -1) 14 { 15 if ((ops+20) % 40 == 0) { 16 printf("%d %d\n", ops, x); 17 signal += ops * x; 18 } 19 if (line[0] == 'a') { 20 ops++; 21 if ((ops+20) % 40 == 0) { 22 printf("%d %d\n", ops, x); 23 signal += ops * x; 24 } 25 int a = atoi(line+5); 26 x += a; 27 printf("%d\n", a); 28 } 29 ops++; 30 } 31 32 printf("%d\n", signal); 33 }