結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-27 19:16:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 474 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 23,040 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:27:20 |
| 合計ジャッジ時間 | 741 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
17 | printf("%d\n", p-s);
| ~^ ~~~
| | |
| int long int
| %ld
main.cpp:25:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
25 | printf("%d\n", p-s+2);
| ~^ ~~~~~
| | |
| int long int
| %ld
main.cpp:5:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%s",s);
| ~~~~~^~~~~~~~
ソースコード
#include<cstdio>
int main(void) {
int n,k;
scanf("%d%d",&n,&k);
k--;
char s[20000];
scanf("%s",s);
int d=0,dd;
char *p;
if(s[k] == '(') {
p = s+k;
do {
if(*p++=='(') d++; else d--;
} while(d);
printf("%d\n", p-s);
return 0;
}
else {
p = s+k;
do {
if(*p--==')') d++; else d--;
} while(d);
printf("%d\n", p-s+2);
return 0;
}
}