結果

問題 No.592 括弧の対応 (2)
ユーザー ohreitetsu
提出日時 2017-11-12 17:16:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 872 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 61,052 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-24 23:15:22
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	string s;
	int sLen;
	cin>>sLen;
	cin>>s;
	vector<int> aw(sLen,0);
	int i=0;
	int LeftIndex=0;
	int LeftNum=0;
	while (sLen>0){
		if (s[i]=='('){
			LeftIndex=i;
			LeftNum++;
		}else if (s[i]==')'){
			LeftNum--;
			aw[LeftIndex]=i;
			aw[i]=LeftIndex;
			s[LeftIndex]=' ';
			s[i]=' ';
			sLen-=2;
			if (LeftNum>0){
				while (LeftIndex>0 && s[LeftIndex]==' '){
					LeftIndex--;
				}
			}
		}
		i++;
	}
	for (i=0;i<aw.size();i++){
		cout<<aw[i]+1<<endl;
	}
	return 0;
}
0