zoukankan      html  css  js  c++  java
  • 实验三

    一、        实验目的

    1、掌握有穷状态自动机的概念;  
    2、掌握有穷状态自动机的存储及表示方法;
    3、掌握有穷状态自动机与正则式之间的关系。
     
    实验内容和要求

    1、输入正规式; 

    2、构造该正规式的有穷状态自动机;

    3. 以五元组形式输出。

    练习:

    ²  (a|b)*abb

    ²  l(l|d)*

    ²  1(1010*|1(010)*1)*0

     



    #include <stdio.h> //s为初态,z为终态 int in(int s,int z) { if(s == z) { printf("3 look!the last status belongs to Z"); return 1; } else { return 0; } } //s为状态,t为输入的字符 int step(int s,char t) { if(t == 'a') switch(s) { case 0:return 1; case 1:return 3; case 2:return 1; case 3:return 3; } else if(t == 'b') switch(s) { case 0:return 2; case 1:return 2; case 2:return 3; case 3:return 3; } } int realize(char *input) { int z = 3; int s,i; s = 0; for(i=0;input[i]!=' ';i++) { printf("%2d",s); s = step(s,input[i]); } if(in(s,z)) { return 1; } else { return 0; } } main() { int i; int a; char input[40]; printf("FA=({0,1,2,3},{a,b},M,0,{3}) "); printf("M: "); printf(" M(0,a)=1 M(0,b)=2 "); printf(" M(1,a)=3 M(1,b)=2 "); printf(" M(2,a)=1 M(2,b)=3 "); printf(" M(3,a)=3 M(3,b)=3 "); printf("请输入你要检查的串"); lop: for(i=0;input[i-1] != ' ';i++) { scanf("%c",&input[i]); } for(i=0;input[i-1]!=' ';i++) { if(input[i] != 'a'&&input[i] != 'b'&&input[i] != ' ') { printf("input error,enter again please: "); goto lop; } } printf("the status sequence is : "); a = realize(input); if(a == 1) printf(" So this string can be identified "); else printf(" So this string can't be identified "); printf("press enter to exit the program "); getchar(); }



    很难弄,理解起来也有困难,有点蒙
  • 相关阅读:
    网络编程
    Ant path 匹配原则
    Android Html.fromhtml
    android AsyncTask
    Android 系统联系人相关URI
    Android 学习心得体会
    中国天气网api(json格式)
    android:textAppearance
    Android COLLATE LOCALIZED ASC
    Android 快递接口
  • 原文地址:https://www.cnblogs.com/a13798508446/p/6103120.html
Copyright © 2011-2022 走看看