Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.