#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!=' ') { if(ch=='/') { a[i][j]=' '; j=0; i++; ch=getchar(); continue; } a[i][j]=ch; j++; ch=getchar(); } a[i][j]=' '; number=2; for(k=0;k<=i;k++) { l=0; m=1; while(a[k][l]!=' ') { if(a[k][l]=='.'||a[k][l]=='*') { if(a[k][l]=='.'&&m==1) { m++; printf("f(0,%c)=%d ",a[k][l-1],number); if(a[k][l+2]==' ') printf("f(%d,%c)=1 ",number,a[k][l+1]); number=number+1; } else if(a[k][l]=='.'&&m!=1) { m++; printf("f(%d,%c)=%d ",number-1,a[k][l-1],number); if(a[k][l+2]==' ') printf("f(%d,%c)=1 ",number,a[k][l+1]); number=number+1; } else if(a[k][l]=='*'&&m==1) { m++; printf("f(0,~)=%d ",number); printf("f(%d,%c)=%d ",number,a[k][l-1],number); if(a[k][l+1]==' ') printf("f(%d,~)=1 ",number); else printf("f(%d,~)=%d ",number,number+1); number=number+1; } else if(a[k][l]=='*'&&m!=1) { m++; printf("f(%d,%c)=%d ",number,a[k][l-1],number); if(a[k][l+1]==' ') printf("f(%d,~)=1 ",number); else printf("f(%d,~)=%d ",number,number+1); number=number+1; } } l++; } } }