[此贴子已经被作者于2004-12-04 20:42:05编辑过]
是一种简单的计算机模型,一种数学模型!我总结不出更简单的解释
花了我几天时间才搞出来了这个鬼东西,其实很简单,只是我说的吓人,live41你如果知道自动机是怎么回事一定很快就会搞出来.
这是我的拙作,我同学做的比我就好多了。
#include<iostream.h> main() { int s,c,i,j,k,x,y,m,n,o; int a[10][10]; int b[10],d[10]; cout<<"Enter how many state:"; cin>>s; for(j=1;j<=s;j++) { cout<<"Enter the state"<<j<<":"; cin>>b[j]; cout<<"State"<<j<<"="<<b[j]<<"\n"; } cout<<'\n'; cout<<"Which is the first state:"; cin>>n; cout<<n<<'\n'; cout<<"Which is the last state:"; cin>>m; cout<<m<<'\n';
cout<<"Enter the states connect.(0=no connect,1=a,2=b)"<<'\n'; for(i=1;i<=s;i++) { for(j=1;j<=s;j++) { cout<<"Enter the a["<<i<<"]["<<j<<"] state's connect:"; cin>>c; a[i][j]=c; cout<<"a["<<i<<"]["<<j<<"]"<<"="<<a[i][j]<<'\n'; } }
cout<<"Enter how many characters:"; cin>>y; for(k=1;k<=y;k++) { cout<<"Enter characters:"; cin>>x; d[k]=x; cout<<"d["<<k<<"]="<<x<<'\n'; cout<<'\n'; } o=n; for(k=1;k<=y;k++) { cout<<"d["<<k<<"]="<<d[k]<<'\n'; cout<<"k="<<k<<'\n'; for(i=o;i<=s;i++) { cout<<"D["<<k<<"]="<<d[k]<<'\n'; cout<<"i="<<i<<'\n'; int t=0; for(j=1;j<=s;j++) { cout<<"D["<<k<<"]="<<d[k]<<'\n'; cout<<"i="<<i<<",j="<<j<<'\n'; //int t=0; if(d[k]==a[i][j]) { o=b[j]; cout<<"d("<<k<<")="<<d[k]<<'\n'; cout<<"a["<<i<<"]["<<j<<"]"<<"="<<a[i][j]<<'\n'; cout<<o<<'\n'; cout<<'\n'; t=1; break; } //if (t=1) // break; else continue; } if(t=1) break; } } cout<<o<<'\n'; if(o==m) cout<<"The characters is accept by this zhidongji."<<'\n'; else cout<<"The characters isn't accept by this zhidongji."<<'\n'; return 0; }