結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2018-06-06 22:53:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 5,000 ms |
コード長 | 608 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 65,636 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:31:29 |
合計ジャッジ時間 | 1,172 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <string> #include <string.h> using namespace std; char ch; int K; void deal(string S) { char *pStr=(char*)S.c_str(); char *p=pStr; char *q=p+1; int x=-1; int y=-1; while (*q!='\0'){ if (*q==')'){ x=(int)(p-pStr+1); y=(int)(q-pStr+1); *p=' '; *q=' '; p=pStr; q=p+1; }else if (*q==' '){ q++; }else{ p=q; q++; } if (ch=='(' && x==K){ cout<<y<<endl; return; } if (ch==')' && y==K){ cout<<x<<endl; return; } } } int main(int argc, char* argv[]) { int N; cin>>N>>K; string S; cin>>S; ch=S[K-1]; deal(S); return 0; }