码迷,mamicode.com
首页 > 其他好文 > 详细

实验三 有限自动机的构造与识别

时间:2016-11-30 13:52:50      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:image   end   har   ring   实验   scan   log   stdio.h   include   

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 101
int n=1;
void tackBack(char ch[],int start,int end,int begain,int final);
int main(){
    char ch[MAX];
    int size;
    scanf("%s",ch);
    size=strlen(ch);
    tackBack(ch,0,size,0,1);
    return 0;
}

void tackBack(char ch[],int start,int end,int begain,int final)
{
    
    int i=start;    
    while(!(ch[i] == |) && i<end)
        i++;
    if(ch[i]==|){
        tackBack(ch,start,i-1,begain,final);
        tackBack(ch,i+1,end,begain,final);    
    }
    i=start;
    //printf("start=%d\tend=%d\n",start,end);
    
    if(ch[i]>=a && ch[i]<=z)
    {
        if(ch[i+1]==.)
        {
            n++;
            printf("f<%d,%c>=%d\n",begain,ch[i],n);                
        }
        else if(ch[i+1]==*)
        {
            n++;
            printf("f(%d,~)=%d\n",begain,n);
            printf("f(%d,~)=%d\n",n,final);
            printf("f(%d,%c)=%d\n",n,ch[i],n);
        }
    }    
    i+=2;
    while(i<end)
    {
        if(ch[i]>=a && ch[i]<=z)
        {
            if(ch[i+1]==.)
            {
                printf("f<%d,%c>=%d\n",n,ch[i],n+1);        
                n++;
            }
            else if(ch[i+1]==*)
            {
                n++;
                printf("f(%d,~)=%d\n",begain,n);
                printf("f(%d,~)=%d\n",n,final);
                printf("f(%d,%c)=%d\n",n,ch[i],n);
            }
        }    
        i++;
    }
    if(ch[i]>=a && ch[i]<=z)
    {
        
        if(ch[i+1]==*)
        {
            printf("f(%d,%c)=%d\n",n,ch[i],final);
        }
        else
        {
            printf("f<%d,%c>=%d\n",n,ch[i],final);
        }
    }

}

实验结果

技术分享

实验三 有限自动机的构造与识别

标签:image   end   har   ring   实验   scan   log   stdio.h   include   

原文地址:http://www.cnblogs.com/wxf2/p/6117196.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!