C
#include "stdio.h"
int main() {
int i = 0;
while (1) {
int c = getchar();
i ++;
switch (i) {
case 1:
if (c != 100) i = 0;
continue;
case 2:
if (c != 114) i = 0;
continue;
case 3:
if (c != 97) i = 0;
continue;
case 4:
if (c != 119) i = 0;
continue;
case 5:
if (c != 33) i = 0;
continue;
default:
puts("bang!");
}
break;
}
}
Compiled with gcc -O3 -o foobar foobar.c
, run with ./foobar
(I'm on Windows, so the -o
and ./foobar
is a guess).
A variation on Hyper Neutrino'shyper-neutrino's solution. Uses a switch statement instead of indexing into a string. Hopefully, this makes it faster.