Re:

http://d.hatena.ne.jp/yaneurao/20051125 : コードを短くするのって楽しいですよね?(1)


やねう企画入社試験のときは解答発表の前日とか出遅れましたが、今回は大丈夫(ですよね?^^;)
うーん、1046byteになりました。
200byteを切ろうという方も居るようで…。
いま108byteなそうです。


というかmain関数部分で既に400byte超えてるんですが。・゚・(ノ∀`)・゚・。

struct tree {
    tree* parent;
    tree* child1;
    tree* child2;

    int sum;

    ~tree() {
        delete child1;
        delete child2;
    }
}

int n;      // 入力した数字


tree* parse(tree* parent) {
    int value;

    switch(getc()) {
    case EOF:
        return null;
    case '(':
        value = getnum(), getc();
        if (value==NONE) {
            return null;
        } else {
            return create(parent, value);
        }
    }
}

tree* create(tree* parent, int value) {
    tree* a = parse(parent);
    tree* b = parse(parent);

    int sum = value + (parent? parent->sum: 0);

    if (!a && !b) {
        if (sum==n) {
            output("yes ");
        }
        return null;
    }

    tree* ret   = new tree();
    ret->parent = parent;
    ret->child1 = null;
    ret->child2 = null;
    ret->sum    = sum;

    if (a)  ret->child1 = a;
    if (b)  ret->child2 = b;

    return ret;
}


main() {
    /**
        getc() = 1文字取得してポインタをインクリメント
        getnum() = 数値を一列取得してポインタをインクリメント
    */

    remove();           // スペースやら改行を削除
    n = getnum():       // 入力した数値

    delete create(null, 0);

    if (no_output) {
        output("no");
    }

    // 複数見付かった場合は下のようにスペースを挟んで回数分表示
    // yes yes
}


# こっそりいろいろ修正^^;