結果
問題 |
No.22 括弧の対応
|
ユーザー |
![]() |
提出日時 | 2015-05-21 20:21:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 743 ms |
コンパイル使用メモリ | 67,120 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:01:08 |
合計ジャッジ時間 | 1,118 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <algorithm> #include <functional> #include <string> #include <limits.h> #include <vector> #include <numeric> using namespace std; int main(){ int max,target; string data; vector<int> loc(10000); int i; cin >> max >> target >> data; //位置保存 for(int i=0; i<max; i++){ loc[i] = i + 1; } //解法2どんどん消してく。 while(true){ //()を探す i = 0; while(i+1 < data.length() && (data[i] != '(' || data[i+1] != ')')){ i ++; } if(data[i] == '(' && data[i+1] == ')'){ if(loc[i] == target){ cout << loc[i+1] << endl; break; }else if(loc[i+1] == target){ cout << loc[i] << endl; break; }else{ data.erase(data.begin() + i, data.begin() + i + 2); loc.erase(loc.begin() + i, loc.begin() + i + 2); } } } return 0; }