結果

問題 No.592 括弧の対応 (2)
ユーザー hamrayhamray
提出日時 2017-11-10 22:57:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 67,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 13:07:10
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 276 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
using namespace std;
int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    stack<char> leftstk;
    stack<char> rightstk;
    stack<int> lnum;
    stack<int> rnum;
    for(int i = 0; i < N; i++){
        if(S[i] == '('){
            leftstk.push(S[i]);
            lnum.push(i);
        }else if(S[i] == ')'){
            rightstk.push(S[i]);
            rnum.push(i);
            if(leftstk.top() == '('){
                cout << rnum.top()  + 1<< endl;
                cout << lnum.top()  + 1<< endl;
                lnum.pop();
                rnum.pop();
                leftstk.pop();
                rightstk.pop();
            }
        }
    }
        return 0;
    }
                   
                   
                
0