結果

問題 No.22 括弧の対応
ユーザー xuelei
提出日時 2018-07-23 11:49:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 411 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 61,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:32:45
合計ジャッジ時間 1,113 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:11: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     }else if(b==k){
      |           ^~
main.cpp:25:15: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |       cout << a << endl;
      |               ^

ソースコード

diff #

#include <iostream>
#include <stack>
using namespace std;

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;

  stack<int> No;

  for(int i=0;i<s.size();i++){
    int a,b;
    if(s[i]=='('){
      No.push(i+1);
    }else{
      a=No.top();
      b=i+1;
      No.pop();
    }
    if(a==k){
      cout << b << endl;
      return 0;
    }else if(b==k){
      cout << a << endl;
      return 0;
    }

  }
}
0