文章
1
粉丝
153
获赞
2
访问
2.2k
 
不用建树的做法,直接判断两个序列每次分开的左右子树不为空的话,其左右子树第一位是否相等即可 。
#include <iostream>
#include <vector>
using namespace std;
#define SIZE 10
int judge(int* a, int x, int* b, int y);
int main(void)
{
    int N;
    int bst[SIZE], tgt[SIZE];
    while(cin>>N){
        if (N == 0)
            break;
        string a;
        cin >> a;
        int len = a.size();
        for (int i = 0; i < len; i++) {
            bst[i] = a[i] - '0';
        }
        for (int i = 0; i < N; i++) {
            string b;
            cin >> b;
            for (int j = 0; j < len; j++) {
                tgt[j] = b[j] - '0';
            }
            int n = a.size();
            if (judge(bst, n, tgt, n))
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}
int judge(int* a, int x, int* b, int y)
{
    if (x != y)
        return 0;
    if (x == 0 && y == 0) {
        re...
    
登录后发布评论
暂无评论,来抢沙发