結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-07-15 11:34:32 |
言語 | C90 (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 698 bytes |
コンパイル時間 | 113 ms |
コンパイル使用メモリ | 21,248 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:02:47 |
合計ジャッジ時間 | 835 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:6:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d %d", &N, &K); | ^~~~~~~~~~~~~~~~~~~~~~ main.c:8:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | scanf("%s", S); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> int main(void){ int i, stack = 0, N, K; scanf("%d %d", &N, &K); char S[N]; scanf("%s", S); if(S[K-1]=='('){ for(i=K-1;i<N;i++){ if(S[i]=='('){ stack++; }else{ stack--; } if(stack==0){ printf("%d\n", i+1); break; } } }else{ for(i=K-1;i>=0;i--){ if(S[i]==')'){ stack++; }else{ stack--; } if(stack==0){ printf("%d\n", i+1); break; } } } return 0; }