結果

問題 No.592 括弧の対応 (2)
ユーザー newlife171128newlife171128
提出日時 2017-12-24 15:58:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 472 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 71,752 KB
実行使用メモリ 4,628 KB
最終ジャッジ日時 2023-08-22 18:01:13
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>

using namespace std;

int main() {

	int n =0;
	cin>>n;

	int pair[n] ={};
	string s;
	cin>>s;

	stack<int> p;

	for(int i=0; i<s.length(); i++){
		if(s[i] == '('){
			p.push(i);
		}
		if(s[i] == ')'){
			pair[p.top()] =i+1;
			pair[i] = p.top()+1;
			p.pop();
		}
	}
	for(int i=0; i<s.length(); i++){
		cout<<pair[i]<<endl;
	}
return 0;
}

0