zoukankan      html  css  js  c++  java
  • 自动机

    #include<stdio.h>
    #define N 100
    main()
    {
    	int j=0;
    	int sum=0;
    	int i;
    	char a[N];
    	printf("请输入一个文法(以#号结束):\n");
    	for(i=0;i<10;i++)
    	{
    		scanf("%c",&a[i]);
    		j++;
    		if(a[i]=='#')
    			break;
    	}
    	/*for(i=0;i<j-1;i++)
    	{
    		printf("%c",a[i]);
    	}*/
    	for(i=0;i<100;i++)
    	{
    		if(a[i]=='|')
    		{
    			printf("\nf(%d,%c)=%d",sum,a[i-1],sum+1);
    			printf("\nf(%d,%c)=%d",sum,a[i+1],sum+1);
    			sum=sum+1;
    		}
    		else if(a[i]=='*')
    		{
    			printf("\nf(%d,$)=%d",sum,sum+1);
    			sum=sum+1;
    			printf("\nf(%d,%c)=%d",sum,a[i-1],sum);
    			printf("\nf(%d,$)=%d",sum,sum+1);
    			sum=sum+1;
    		}
    		else if((a[i]<='z')&&(a[i]>='a')&&(a[i+1]<='z')&&(a[i+1]>='a'))
    		{
    			if(a[i+2]=='|')
    			{
    				printf("\nf(%d,%c)=%d",sum,a[i],sum+1);
    				sum=sum+1;
    				printf("\nf(%d,%c)=%d",sum,a[i+1],sum+1);
    				printf("\nf(%d,%c)=%d",sum,a[i+3],sum+1);
    				sum=sum+1;
    				i=i+2;
    			}
    			else if(a[i+2]=='*')
    			{
    				printf("\nf(%d,%c)=%d",sum,a[i],sum+1);
    				sum=sum+1;
    				printf("\nf(%d,$)=%d",sum,sum+1);
    				sum=sum+1;
    				printf("\nf(%d,%c)=%d",sum,a[i+1],sum);
    				printf("\nf(%d,$)=%d",sum,sum+1);
    				sum=sum+1;
    				i=i+2;
    			}
    			else
    			{
    				printf("\nf(%d,%c)=%d",sum,a[i],sum+1);
    				sum=sum+1;
    				printf("\nf(%d,%c)=%d",sum,a[i+1],sum+1);
    				sum=sum+1;
    			}
    		}
    
    
    
    	}
    
    
    }
  • 相关阅读:
    MessageFormat理解,MessageFormat.format(Object obj)方法
    正则表达式
    数字处理类
    包装类
    遍历Map的4种方法(来自网络)
    集合类
    数组
    字符串
    语言基础
    Linux下使用openssl加解密
  • 原文地址:https://www.cnblogs.com/dalaotan/p/5044873.html
Copyright © 2011-2022 走看看