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

📄 dfa.cpp

📁 编译原理试验
💻 CPP
字号:
#include<iostream>
using namespace std;

char DFA[3][3]={
	{'b','a','c'},
    {'c','a','b'},
	{'b','a','b'}
};

int testDFA(char , int );
void main()
{
	cout<<"the regExpression is (a|b)*ab"<<endl;
	cout<<"please input your string number"<<endl;
	int num=0;
	cin>>num;
	char *a;
    a = new char[num]; 
	cout<<"string"<<endl;

	for(int i=0;i<num;i++)
	{
	    cin>>a[i];
	}

	int c= 0 ,n= 1;
	for(int q=0;q< num; q++)
		cout<<a[q];
	cout<<endl;
    for(int j=0;j<num; j++)
	{
       n=testDFA(a[j],c);
	   cout<<"State is from "<<c<<" to "<<n<<endl;
	   c =n;
	   if(c==4)
	   {
		   
		   cout<<"the string does not meet the needs."<<endl;
		   break;
	   }

	   
	   
	}
	if(c == 2)
	{
		cout<<"the string meet the needs.";
	}
	else
	{
		 cout<<"the string does not meet the needs."<<endl;
	}
 

}

int testDFA(char x, int cur)
{
	for(int state=0; state< 4; state++)
	{
		if(DFA[cur][state] ==x)
		{
			return state;
		}	
	}
	return 4;
}

⌨️ 快捷键说明

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