#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

struct tree {
    tree *lchild;
    tree *rchild;
    char data;
};
void creatTree(tree *&Tree)
{
    char c;
    cin >> c;
    if (c == '#')
    {
        Tree = NULL;
        return;
    }


    Tree = new tree;
    Tree->data = c;
    creatTree(Tree->lchild);
    creatTree(Tree->rchild);
}

bool flag = false;

void getHeight(tree *Tree, int high, int &h)
{
    if (Tree == NULL)
    {
        return;
    }
    if (high > h)
    {
        h = high;
    }

    if (Tree->lchild != NULL)
    {
        getHeight(Tree->lchild, high + 1, h);
    }
    if (Tree->rchild != NULL)
    {
        getHeight(Tree->rchild, high + 1, h);
    }
}

void solveIt(tree *Tree)
{
    if (flag)
    {
        return;
    }
    if (Tree == NULL)
    {
        return;
    }
    int max1 = 0, max2 = 0;
    getHeight(Tree->lchild, 0, max1);
    getHeight(Tree->rchild, 0, max2);
    if (abs(max1 - max2) > 1)
    {
        flag = true;
        return;
    }
    solveIt(Tree->lchild);
    solveIt(Tree->rchild);
}

int main()
{
    tree *Tree = NULL;
    creatTree(Tree);

    solveIt(Tree);

    if (flag)
    {
        cout << "no!";
    }
    else
    {
        cout << "yes!";
    }
    return 0;
}
最后修改:2019 年 04 月 10 日
如果觉得我的文章对你有用,请随意赞赏