ustc1


私信TA

用户名:ustc1

访问量:1305

签 名:

等  级
排  名 3728
经  验 1778
参赛次数 4
文章发表 2
年  龄 0
在职情况 学生
学  校 科大
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef struct tree
{
    int m;
    struct tree *l;
    struct tree *r;
}T;
void build(T *root,T *s)
{
    if(s->m<root->m)
    {
        if(root->l)
        {
            build(root->l,s);
        }
        else
        {
            root->l=s;
        }
    }
    else if(s->m>root->m)
    {
         if(root->r)
        {
            build(root->r,s);
        }
        else
        {
            root->r=s;
        }
    }
}
int f(T *root1,T *root2)
{
    if(root1==NULL&&root2==NULL)
    {
        return 1;
    }
    else if(root1!=NULL&&root2!=NULL)
    {
        if(root1->m!=root2->m)
        {
            return 0;
        }
        else
        {
            return (f(root1->l,root2->l)&&f(root1->r,root2->r));
        }
    }
}
int main()
{
    int N;
    while(1)
    {
        scanf("%d",&N);
        getchar();
        if(N==0)
        {
            break;
        }
        char a[11];
        char b[11];
        gets(a);
        int l=strlen(a);
        int i;
        T *root1;
        root1=malloc(sizeof(T));
        root1->m=a[0]-'0';
        root1->l=NULL;
        root1->r=NULL;
        for(i=1;i<l;i++)
        {
            T *s;
            s=malloc(sizeof(T));
            s->m=a[i]-'0';
            s->l=NULL;
            s->r=NULL;
            build(root1,s);
        }
        while(N--)
        {
            gets(b);
            T *root2;
            root2=malloc(sizeof(T));
            root2->m=b[0]-'0';
            root2->l=NULL;
            root2->r=NULL;
            int j;
            for(j=1;j<l;j++)
            {
                T *s;
                s=malloc(sizeof(T));
                s->m=b[j]-'0';
                s->l=NULL;
                s->r=NULL;
                build(root2,s);
            }
            if(f(root1,root2)==1)
            {
                printf("YES\n");
            }
            else
            {
                printf("NO\n");
            }
        }



    }
    return 0;

}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区