/* p10.c */ #include /* We can also use a state machine model instead of */ /* remembering old values */ /* state meaning */ /* 0 looking for 13 */ /* 1 found 13 looking for 14 */ /* 2 found 14 looking for 15 */ /* 3 found 13, 14, 15 */ int main() { int state; int value; // current value int howmany; // howmany values were read int found = 0; // found target howmany = fscanf(stdin, "%d", &value); while ((howmany == 1) && (state != 3)) { if (value == 13) state = 1; else if ((state == 1) && (value == 14)) state = 2; else if ((state == 2) && (value == 15)) state = 3; else state = 0; howmany = fscanf(stdin, "%d", &value); } if (state == 3) fprintf(stdout, "yes\n"); else fprintf(stdout, "no\n"); return(0); }