the code is for generating a finite automata
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int d[10][10];
/*void compute_transition_function(string P,set<char> s)
{
int m=P.length();
set<char> ::iterator i;
for(int q=0;q<=m;q++)
{
for(i=s.begin();i!=s.end();i++)
{
int k=min(m+1,q+2);
while(k>0)
{
k=k-1;
char c=*i;
string s =P.substr(q-k+1,k-1);
if(k==0)
s="";
s+=c;
cout<<s<<endl;
if(!P.substr(0,k).compare(s))
{d[q][(*i)-'a']=k;
break;}
}
}
}
}*/
void finite_automaton_matcher(string T,int m)
{
int n=T.length() ;
int q=0;
for(int i=0;i<n;i++)
{
q=d[q][T[i]-'a'];
if(q==m)
cout<<"Pattern occurs with shift "<<i-m<<endl;
}
}
int main()
{
string text="abcabaabcaabaaababacabac";
string pattern ="ababaca";
set<char> s;
s.insert('a');
s.insert('b');
s.insert('c');
int m=pattern.length();
set<char> ::iterator i;
for(int q=0;q<=m;q++)
{
for(i=s.begin();i!=s.end();i++)
{
int k=min(m+1,q+2);
while(k>0)
{
k=k-1;
char c=*i;
string s =pattern.substr(q-k+1,k-1);
if(k==0)
s="";
s+=c;
cout<<s<<endl;
if(!pattern.substr(0,k).compare(s))
{d[q][(*i)-'a']=k;
break;}
/*here should be the error*/
}
}
}
finite_automaton_matcher(text,pattern.length());
return 0;
}
please help!!