結果

問題 No.22 括弧の対応
ユーザー kongarishisyamo
提出日時 2016-02-26 00:39:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 433 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 62,072 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:09:26
合計ジャッジ時間 1,244 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stack>
#include<string>

using namespace std;

int main(){

	stack<int> data;
	int N,K;
	string s;

	cin>>N>>K;
	cin>>s;

	for(int i=0;i<N;i++){
		if(s[i]=='(') data.push(i+1);
		if(s[i]==')'){
			if(data.empty()){
				cout<<"error data"<<endl;
				return 0;
			}
			if(data.top()==K||i+1==K){
				cout<<((i+1==K)?data.top():i+1)<<endl;
				return 0;
			}
			data.pop();
		}
	}

	cout<<"NO MATCH"<<endl;
}
0