sclass SuperPrecise { sclass C { char c; bool output; *() {} *(char *c, bool *output) {} } S poemID; new L script; int i = 0; bool fail; new StringBuilder out; *(S *poemID) { for (E e : parsePoem(poemID)) { if (e.q != null) addInput(e.q + "\n"); else if (e.a != null) addOutput(e.a + "\n"); } loop(); } // probably remove this void loop() { printOut(); S line; while ((line = readLine()) != null) { for (char c : chars(line + "\n")) onIncomingCharacter(c); printOut(); } } void addOutput(S text) { for (char c : asChars(text)) script.add(new C(c, true)); } void addInput(S text) { for (char c : asChars(text)) script.add(new C(c, false)); } void onIncomingCharacter(char c) { if (fail || get(script, i) == null) charPut('?'); else { C x = get(script, i); assertFalse(x.output); if (c == x.c) { ++i; printOut(); } else { fail = true; charPut('?'); } } } void printOut() { while (!fail && get(script, i) != null && get(script, i).output) charPut(get(script, i++).c); //charPut_flush(); } void charPut(char c) { out.append(c); } }