#include #include #include int main(void) { int depth = 0; int pos = 0; int val; char comm[256]; while(scanf("%255s %d\n", comm, &val) != EOF) { if (!strcmp(comm, "forward")) { pos += val; } else if (!strcmp(comm, "up")) { depth -= val; } else if (!strcmp(comm, "down")) { depth += val; } else { fprintf(stderr, "bad command: %s\n", comm); exit(1); } } printf("%d\n", pos * depth); return 0; }