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