結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
sasa
|
| 提出日時 | 2025-03-06 16:45:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 600 bytes |
| コンパイル時間 | 405 ms |
| コンパイル使用メモリ | 28,032 KB |
| 実行使用メモリ | 8,484 KB |
| 最終ジャッジ日時 | 2025-03-06 16:45:12 |
| 合計ジャッジ時間 | 1,455 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘char (*)[10010]’ [-Wformat=]
8 | scanf ("%s",&str);
| ~^ ~~~~
| | |
| | char (*)[10010]
| char*
main.cpp:7:11: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf ("%d %d",&length,&des);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:8:11: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf ("%s",&str);
| ~~~~~~^~~~~~~~~~~
In file included from /usr/include/stdio.h:980,
from main.cpp:1:
In function ‘int printf(const char*, ...)’,
inlined from ‘int main()’ at main.cpp:42:11:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:86:23: warning: ‘answer’ may be used uninitialized [-Wmaybe-uninitialized]
86 | return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:12:9: note: ‘answer’ was declared here
12 | int answer;
| ^~~~~~
ソースコード
#include <stdio.h>
int main(void) {
char str[10010];
int length,des;
scanf ("%d %d",&length,&des);
scanf ("%s",&str);
int right,left;
int vec;
int answer;
right=0;
left=0;
if (str[des-1] == '(') {
for (int i = des-1; i < length; i++) {
if ( str[i] == '('){
right++ ;
}else{
left++ ;
}
if (right==left) {
answer=i+1;
break;
}
}
} else {
for (int i = des-1; i >= 0; i--) {
if ( str[i] == '('){
right++ ;
}else{
left++ ;
}
if (right==left) {
answer=i+1;
break;
}
}
}
printf("%d\n",answer);
}
sasa