129-有确定性的有穷自动机

#include <stdio.h>  //s为初态,z为终态
int in(int s,int z)
{
    if(s == z)
    {
        printf("3\nlook!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]!=‘\n‘;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})\n");
    printf("M:\n");
    printf("    M(0,a)=1    M(0,b)=2\n");
    printf("    M(1,a)=3    M(1,b)=2\n");
    printf("    M(2,a)=1    M(2,b)=3\n");
    printf("    M(3,a)=3    M(3,b)=3\n");
    printf("请输入你要检查的串");
lop:
    for(i=0;input[i-1] != ‘\n‘;i++)
    {
        scanf("%c",&input[i]);
    }
    for(i=0;input[i-1]!=‘\n‘;i++)
    {
        if(input[i] != ‘a‘&&input[i] != ‘b‘&&input[i] != ‘\n‘)
        {
            printf("input error,enter again please:\n");
            goto lop;
        }
    }         printf("the status sequence is :\n");
    a = realize(input);
    if(a == 1)
        printf("\nSo this string can be identified\n");
    else
        printf("\nSo this string can‘t be identified\n");
    printf("press enter to exit the program\n");
    getchar();
}
时间: 2024-08-01 21:47:01

129-有确定性的有穷自动机的相关文章

131-有确定性的有穷自动机

#include <stdio.h> //s为初态,z为终态 int in(int s,int z) { if(s == z) { printf("3\nlook!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:ret

有确定性的有穷自动机

#include <stdio.h> //s为初态,z为终态 int in(int s,int z) { if(s == z) { printf("3\nlook!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:ret

107-有确定性的有穷自动机

#include <stdio.h> //s为初态,z为终态 int in(int s,int z) { if(s == z) { printf("3\nlook!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:ret

字符串匹配算法 之 基于DFA(确定性有限自动机)

确定有限自动机定义:http://en.wikipedia.org/wiki/Deterministic_finite_automaton 自动机在字符串匹配中的应用 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define ALPHABETLENGTH 53 5 #define GETMIN(x,y) ((x)<=(y)?(x):(y)) 6 7 //判定pattern的前k个

[2016-02-19][UVA][129][Krypton Factor]

UVA - 129 Krypton Factor Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description You have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physica

NOTES : A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung

NOTES :  A Model of Gas Exchange for Hyperpolarized Xe(129) Magnetic Resonance of the Lung  背景知识: Gas exchange is the essential function of the lung. In general, a lung can be viewed as a porous medium(多孔介质) consisting of capillary(毛细管) circuits with

确定性这剂毒药,你喝过没

假如你如今想换工作,你会怎么选择呢?薪水够多.工作够轻松,不加班,目标职位须要的技能你又刚好会,离家近,奖金多?满足这样要求的单位就能够去了.去了就会如你所愿一切都非常美好? 假如你是个程序猿,不想做软件开发了,想转行.有几个选择:IT培训讲师.NLP教练.开咖啡馆.淘宝开店卖家具.你会选择哪个? 我去參加职业规划师的培训,同期的学员中有非常多都是在单位里从事某种工作,HR.財会.猎头.开发.引导师,这里面会有多少人立刻出来专门从事职业规划师这个职业?我和几位老师聊过,由于所处地域的市场还在培育

正规式转换为有穷自动机

1 #include<stdio.h> 2 #include <ctype.h> 3 #define ok 1 4 #define error 0 5 #define MAXREGLUARLONG 40 6 #define MAXSTATELONG 40 7 #define MAXCAHRSLONG 40 8 typedef int state; 9 int iCurrentState=0; //初态以1开始 10 int iPreState=0; 11 int iLastFork

[转] 确定性投资的框架

yanhaijin - http://blog.sina.com.cn/s/blog_4e9b6f470102v7qy.html 过去我多次谈及自己的投资框架,随着更多地投资实践,越来越意识到确定性的重要性.我本人是非常讨厌交流投资理念的,我一直奉行的也是适合自己的就是最好的.对于确定性投资的思考,仅适用于我本人. 理解“确定性”,应该从它的对立面“不确定性”来着手.所谓“不确定性”,更多是风险层面的常用词汇,指我们没有足够的知识来描述当前的状况或者估计将来的结果.所以,确定性,简单来说,就是我