这什么离谱错误

这是啥WA... 评测机在自我否定吗 :sweat_smile:

1 条评论

  • @ 2021-01-20 17:32:08

    代码丢这儿了...

    #include <bits/stdc++.h>
    using namespace std;
    struct node {
        char v = 0;
        node *l = nullptr, *r = nullptr;
    };
    node *in_nodes[10];
    node *pos_nodes[10];
    
    node *buildTree(int inStart, int inEnd, int posStart, int posEnd) {
        if (inStart >= inEnd || posStart >= posEnd)return nullptr;
        node *root = pos_nodes[posEnd - 1];
        int index = inStart;
        while (in_nodes[index]->v != root->v)index++;
    
        root->l = buildTree(inStart, index, posStart, posStart + index - inStart);
        root->r = buildTree(index + 1, inEnd, posStart + index - inStart, posEnd - 1);
        return root;
    }
    
    void prePrint(node *root) {
        if (root == nullptr)return;
        cout << root->v;
        prePrint(root->l);
        prePrint(root->r);
    }
    
    int main() {
        char c;
        int len = 0;
        node *tmp_nodes[256];
        while ((c = getchar()) != '\n') {
            node *tmp = new node();
            tmp->v = c;
            in_nodes[len++] = tmp_nodes[c] = tmp;
        }
        len = 0;
        while ((c = getchar()) != '\n') {
            pos_nodes[len++] = tmp_nodes[c];
        }
        prePrint(buildTree(0, len, 0, len));
        return 0;
    }
    
    

    cout << root->v;改成putchar(root->v);就好了。是评测机的锅嘛?

  • 1

信息

ID
1132
难度
2
分类
数据结构 | 点击显示
标签
递交数
3868
已通过
2196
通过率
57%
被复制
23
上传者