zoukankan      html  css  js  c++  java
  • 有(很)穷的自动机

    #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();

    }

  • 相关阅读:
    你可能不知道的Linux/GNU bash sort多列排序功能
    设置字间距
    设置为灰度图
    点击短信中的url打开某个应用
    AchartEngine绘图引擎
    表格类似Excel
    自定义圆环progressbar
    高低版本方法兼容
    读取并创建excel文件(.xls)
    在android studio中导入github下载的工程
  • 原文地址:https://www.cnblogs.com/huang123/p/5017414.html
Copyright © 2011-2022 走看看