結果

問題 No.22 括弧の対応
ユーザー niquniniquni
提出日時 2016-10-04 21:53:19
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,409 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 54,100 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 12:29:57
合計ジャッジ時間 3,697 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 2 ms
6,940 KB
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

typedef struct parent {
    int num;
    char prt;
    parent *prev;
    parent *next;
} parent;

parent *cons(parent *tail ,int num) {
    parent *n = new parent;
    tail->next = n;
    n->prev = tail;
    n->num = num;
    cin >> n->prt;
    return n;
}

/*void deleteGavage(parent *gavage) {
    parent *tmpgvg = gavage;
    delete tmpgvg->next;
    delete tmpgvg;
}*/

void connectG_list(parent *gtail, parent *g) {
    gtail->next = g;
    g->prev = gtail;
    gtail = g;
    gtail->next = NULL;
}

int main() {
    int n, k;
    char *c;
    parent *p, *head, *tail, *search, *ghead, *gtail;

    cin >> n >> k;

    head = new parent;
    head->num = 1;
    cin >> head->prt;
    head->prev = NULL;
    tail = head;
    for (int i = 2; i <= n; i++) {
        tail = cons(tail, i);
    }
    tail->next = NULL;

    /*while (head != NULL) {
        cout << head->prt;
        head = head->next;
        //cout << "d\n";
        //delete head;
    }*/
    //cout << "\n";
    ghead = new parent;

    ghead->next = NULL;
    ghead->prev = NULL;
    parent *temp0;
    int flag = 0;
    while (flag == 0) {
        search = head;
        while (search != NULL)  {
            if ((search->prt == '(') && (search->next->prt == ')')) {
                if (search->num == k) {
                    cout << search->next->num << "\n";
                    flag = 1;
                }
                else if (search->next->num == k) {
                    cout << search->num << "\n";
                    flag = 1;
                }
                else {
                    //if (search == head) {

                        //deleteGavage(search);

                    //}
                    //else {
                        search->prev->next = search->next->next;
                        search->next->next->prev = search->prev;
                        temp0 = search;
                        delete temp0->next;
                        delete temp0;
                    //}
                    //break;
                }
                break;
            }
            search = search->next;
        }
    }
    //cout << "ok\n";
    parent *temp;
    /*while (ghead != NULL) {
        temp = ghead;
        ghead = ghead->next;
        delete temp;
    }*/
    while (head != NULL) {
        temp = head;
        head = head->next;
        delete temp;
    }


}
0