⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dfamain.cpp

📁 用vc 实现的计算理论的基本程序
💻 CPP
字号:
#include <iostream.h>
#include <string.h>

#define maxstate 20
#define maxendstate 10
#define maxletter 26
#define maxstring 100
 
void main()

{  int statenum,endstatenum,letternum;
    
   int k [maxstate];         
   int f [maxendstate];
   char letter[maxletter];
   int move[maxstate][maxletter];
   int state;
   char instring[maxstring];
   char cuan;

   cout<<"enter  the number of state:";
   cin>>statenum;
   cout<<"enter the number of endstate:";
   cin>>endstatenum;
   cout<<"enter the number of the letter:";
   cin>>letternum;

  
  cout<<"state 0 is the first state"
	  <<endl
	  <<"enter state:(0--statenum-1):" ;    //状态表
	 
  for(int i=0;i<statenum;i++)
	  cin>>k[i];
	  
  cout<<"enter the end state:(0--statenum-1)";       //终结状态
  for(int j=0;j<endstatenum;j++)
  cin>>f[j];

  cout<<"enter the letter:";           //字母表
	  
  for(int t=0;t<letternum;t++)
  cin>>letter[t];

  cout<<"enter the state movement:"<<endl ; //输入转移关系
  cout<<" ";	  
  for(int m=0;m<letternum;m++)
	  cout<<"  "<<letter[m];
  cout<<endl;
 
  for(i=0;i<statenum;i++)
  {
	   cout<<k[i]<<"  ";
       for(j=0;j<letternum;j++)
		   cin>>move[i][j];
  }
  
 
 
 while(1)
 {
  cout<<"enter your string :";       //输入一个字符串如:abcbab等

  cin>>instring ;
  
  int length=strlen(instring);

  cout<<"length of string :"<<length<<endl;

 
  int num=0;
  state=0;
  cout<<"the state movement: "
	  <<state;

  while(length!=0)
  {   
	  cuan=instring[num++];
	  
	  state=move[state][cuan-'a'];
	  cout<<"-->"<<state;
      length--;
	
  } 
 
  cout<<endl;
	  
  for(i=0;i<statenum;i++)          //测试转移判断是否接受字符串
	  if(state==f[i])
	  { cout<<"accept!"
	        <<endl;
	    break;
	    
	  }
	    
if(i==statenum)
    cout<<"can not accept!"<<endl;

 int flag;
 cout<<" to continue your check input 1"
	 <<endl
	 <<" and if you quit please input 0:";
 cin>>flag;	    
 if(flag==0)
	 break;
 }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -