Beispiel #1
0
struct BT *built(int in[] ,int pre[],int start,int n)
	{
		if(start>n)
			return NULL;
			
		
		static int pr=0;
		struct BT *root=nn(pre[pr++]);
		
			
			int i=search(in,start,n,root->data);
			if(start==n)
				return root;
			
		
			else
				{
					root->l=built(in,pre,start,i-1);
					root->r=built(in,pre,i+1,n);
				}
			
		return root;
			
		
		
		
	
	}	
Beispiel #2
0
void LL(node_ptr &head,LinkQueue hword)//
{
	cout<<"LL(1)文法判断:"<<endl;
	
	kong *k=NULL;
	list *first=NULL;
	list *follow=NULL;
	selist *select=NULL;

	built(head,first,follow,1);//建立first
	
	
	builtKong(first,k);//根据first 建立非终结符是否能推出空的表格
	

	built(head,first,follow,0);//建follow
	
	
	builtSelect(head,first,follow,select,k);//建立select
	
	kong *p=k;
	while(p)
	{
		cout<<p->ch<<"  "<<p->b<<endl;
		p=p->next;
	}
	system("pause");

    cout<<"FIRST:"<<endl;
    Display(first);
	system("pause");
	
	cout<<"FOLLOW:"<<endl;
	Display(follow);
	system("pause");
	
	cout<<"SELECT:"<<endl;
	selist *pf=select;
	while(pf)
	{
		cout<<setiosflags(ios_base::left)<<setw(10)<<pf->Vn<<": ";
	    cout<<pf->Vt<<endl;
		
		pf=pf->next;
	}
    system("pause");
	
	judge(select);//通过select判断是否为LL(1)文法
	
	selist *analy=NULL;
	Prediction(select,analy);//通过select建立预测分析表
	Analysis(analy,hword);//通过分析表开始分析
}
int main(){  
#ifdef LOCAL  
    freopen("in.txt", "r", stdin);  
    freopen("out.txt", "w+", stdout);  
#endif  
    Trie root = built();  
    State ret, temp;  
    while (~scanf("%s", ret)){   
        insert(root, ret);   
        strcpy(st[count++], ret);  
    }  
    int i, t = 0;  
    while (t < count){  
        int n = strlen(st[t]);  
        for (i = 0; i < n; i++){  
            strncpy(temp, st[t], (i + 1) * sizeof(char));  
            temp[i + 1] = '\0';  
            if (1 == search(root, temp) || n == i + 1){  
                printf("%s %s\n", st[t], temp);  
                break;  
            }  
        }  
        t++;  
    }  
    return 0;  
}  
Beispiel #4
0
int main(){  
#ifdef LOCAL  
    freopen("in.txt", "r", stdin);  
    freopen("out.txt", "w+", stdout);  
#endif  
    int t, n;  
    State rev;  
    scanf("%d", &t);  
    while (t--){  
        sz = 0;  
        scanf("%d", &n);  
        Trie root = built();  
        int k = n, count = 0, flag = 0;  
        while (k--){  
            scanf("%s", rev);  
            strcpy(st[count++], rev);  
            insert(root, rev);  
        }  
        for (k = 0; k < n; k++){  
            if (search(root, st[k]) > 1){  
                printf("NO\n");  
                flag = 1;  
                break;  
            }  
        }  
        if(!flag) printf("YES\n");  
    }  
    return 0;  
}  
Beispiel #5
0
main()
	{
		int pre[]={3,5,2,6,7,1,4};
		
		int in[]={1,2,3,4,5,6,7};
		
		struct BT *rt;
		
		
		int n=sizeof(pre)/sizeof(pre[0]);
		printf("%d",n);
		rt=built(in,pre,0,n-1);
		
		printf("\n\n");
		inprint(rt);
		
		printf("\n\n");
		
		preprint(rt);
		printf("\n\n");
		
		//struct BT *rt1=builtBT(pre,in,0,n-1);
		//inprint(rt1);
		
		//printf("\n\n");
		
		//preprint(rt1);
		//printf("\n\n");
		
	}	
void built(int L,int R)
{
    if(L>R)return;
    int M=(L+R)>>1;
    ll miX=INF,maX=-INF,miY=INF,maY=-INF;
    for(int i=L; i<=R; i++) {
        miX=min(miX,p[i].x);
        maX=max(maX,p[i].x);
        miY=min(miY,p[i].y);
        maY=max(maY,p[i].y);
    }
    flag[M]=(maX-miX)>=(maY-miY);
    nth_element(p+L,p+M,p+R+1,flag[M]? cmpx:cmpy);
    tree[M]=p[M];
    built(L,M-1);
    built(M+1,R);
}
void insert(Trie T, char *src){  
    char *p = src;  
    while (*p != '\0'){  
        if (T->next[*p - 'a'] == NULL) T->next[*p - 'a'] = built();  
        T = T->next[*p - 'a'];  
        T->cnt++;  
        p++;  
    }  
}  
Beispiel #8
0
CSNODE * built (CSNODE * root)
{
	char ch;

	ch = getchar();

	if (ch == '#')
	{
		return NULL;
	}

	root = (CSNODE *)malloc(sizeof(CSNODE));

	root->data = ch;
	root->Fistchild = built(root->Fistchild);
	root->NextSibing = built(root->NextSibing);

	return root;
}
void insert(Tries T, char *str){  
    char *p = str;  
    while (*p != '\0'){  
        if (T->pNext[*p - 'a'] == NULL){  
            T->pNext[*p - 'a'] = built();  
        }  
        T = T->pNext[*p - 'a'];  
        p++;  
    }  
    T->flag = 1;  
}  
int main()
{
    int T;
    scanf("%d",&T);
    while(T--) {
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++) {
            scanf("%lld%lld",&p[i].x,&p[i].y);
            q[i]=p[i];
        }
        built(0,n-1);
        for(int i=0; i<n; i++) {
            ans=INF;
            fint(0,n-1,q[i]);
            printf("%I64d\n",ans);
        }
    }
    return 0;
}
Beispiel #11
0
int main(int argc, char *argv[])
{
	CSNODE * root;
	int num = 0;
	int tmp = 0;

	root = built(root);

	printf("进入\n");

	visit(root);

	printf("\n");

	height(root, &num, &tmp);

	printf("%d\n", num);

	return EXIT_SUCCESS;
}
Beispiel #12
0
int main(){  
    State buf;  
    Tries root = built();  
    int i, j, count = 0;  
    while (EOF != scanf("%s", buf)) {  
        insert(root, buf);  
        strcpy(ret[count++], buf);  
    }  
    for (i = 0; i < count; i++){  
        int n = strlen(ret[i]);  
        for (j = 1; j < n; j++){  
            State tp1 = { 0 }, tp2 = { 0 };  
            strncpy(tp1, ret[i], j);  
            strncpy(tp2, ret[i] + j, n - j);  
            if (search(root, tp1) && search(root, tp2)){  
                printf("%s\n", ret[i]);  
                break;  
            }  
        }  
    }  
    return 0;  
}