1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-09 11:09:07 +01:00
CodeWars/6kyu/design_a_simple_automaton/solution.cpp
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

36 lines
611 B
C++

#include <map>
#include <set>
class Automaton
{
std::set<int> F{2};
const int initial_state = 1;
std::map<int, std::map<char, int>> transitions{
{1, std::map<char, int>{
{'0', 1}, {'1', 2}
}
},
{2, std::map<char, int>{
{'0', 3}, {'1', 2}
}
},
{3, std::map<char, int>{
{'0', 2}, {'1', 2}
}
}
};
public:
Automaton() {}
bool read_commands(const std::vector<char>& commands) {
int state = initial_state;
for (const char c : commands) {
state = transitions[state][c];
}
return F.find(state) != F.end();
}
};