Fixed algorithm and added main.cpp. automaton needs to be refined.