Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- S -> BAC
- B -> w
- A -> qA | q
- C -> S | l
- */
- #include <iostream>
- #include <stdexcept>
- using namespace std;
- int c;
- void gc() {
- c = getchar();
- }
- void B() {
- if (c != 'w') {
- throw runtime_error("B failed");
- }
- gc(); // потому что проверили терминал
- }
- void A() {
- if (c != 'q') {
- throw runtime_error("A failed");
- }
- gc();
- while (c == 'q') {
- gc();
- }
- }
- void S(); // обязательно декларировать перед C, чтобы использовать ее в C, потому что C используется в S, а S в C
- void C() {
- if (c == 'l') {
- gc();
- return;
- }
- if (c == 'w') {
- S();
- return;
- }
- throw runtime_error("C failed");
- }
- void S() {
- B();
- A();
- C();
- }
- int main() {
- try {
- gc(); // считываем первый символ и покрутились
- S();
- cout << "YES" << endl;
- } catch (runtime_error ex) {
- cout << "NO: " << ex.what() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement