自动转换机

#include<stdio.h>
#define MAX 20
main()
{
    int i=0,j=0,k,l,m,n,number;
    char ch;
    char a[MAX][MAX];
    printf("请输入正规式:");
    ch=getchar();
    while(ch!='\n')
    {
        if(ch=='/')
        {
            a[i][j]='\0';
            j=0;
            i++;
            ch=getchar();
            continue;
        }
        a[i][j]=ch;
        j++;
        ch=getchar();
    }
    a[i][j]='\0';

    number=2;
    for(k=0;k<=i;k++)
    {
        l=0;
        m=1;
        while(a[k][l]!='\0')
        {
            if(a[k][l]=='.'||a[k][l]=='*')
            {

               if(a[k][l]=='.'&&m==1)
               {
                 m++;
                 printf("f(0,%c)=%d\n",a[k][l-1],number);
                 if(a[k][l+2]=='\0')
                  printf("f(%d,%c)=1\n",number,a[k][l+1]);
                 number=number+1;
               }

               else if(a[k][l]=='.'&&m!=1)
               {
                   m++;
                   printf("f(%d,%c)=%d\n",number-1,a[k][l-1],number);
                   if(a[k][l+2]=='\0')
                    printf("f(%d,%c)=1\n",number,a[k][l+1]);
                    number=number+1;
               }

               else if(a[k][l]=='*'&&m==1)
               {
                   m++;
                   printf("f(0,~)=%d\n",number);
                   printf("f(%d,%c)=%d\n",number,a[k][l-1],number);
                   if(a[k][l+1]=='\0')
                    printf("f(%d,~)=1\n",number);
                   else
                    printf("f(%d,~)=%d\n",number,number+1);
                   number=number+1;
               }

               else if(a[k][l]=='*'&&m!=1)
               {
                    m++;
                   printf("f(%d,%c)=%d\n",number,a[k][l-1],number);
                   if(a[k][l+1]=='\0')
                    printf("f(%d,~)=1\n",number);
                   else
                    printf("f(%d,~)=%d\n",number,number+1);
                   number=number+1;
               }
            }
            l++;
        }
    }


}

  

posted @ 2016-11-30 13:00  风丶轻轻  阅读(124)  评论(0编辑  收藏  举报