Skip to content

Instantly share code, notes, and snippets.

@lascar-pacagi
Created December 19, 2019 22:13
Show Gist options
  • Save lascar-pacagi/e2ac6243986672d9c85a839f26eadc52 to your computer and use it in GitHub Desktop.
Save lascar-pacagi/e2ac6243986672d9c85a839f26eadc52 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<vector<int>> dfa
{
// a b
/*0*/ { 1, 0 },
/*1*/ { 1, 2 },
/*2*/ { 3, 0 },
/*3*/ { 1, 2 },
};
int state = 0;
char c;
while (cin >> c) {
state = dfa[state][c - 'a'];
}
cout << "Input is " << (state == 3 ? "" : "not ") << "in the language\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment