結果

問題 No.22 括弧の対応
ユーザー A63295A63295
提出日時 2015-12-26 17:31:11
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 20,480 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:06:40
合計ジャッジ時間 840 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:6:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 | scanf ("%d%d", &N, &K);
      | ^~~~~~~~~~~~~~~~~~~~~~
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf ("%s",&S[i]);
      |         ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int main(void){
int i = 0, k = 0, l = 1;
int N = 0, K = 0;
char S[10000];
scanf ("%d%d", &N, &K);
for ( i = 0; i < N; i++){
	scanf ("%s",&S[i]);
}

if ( S[K - 1] == '('){
	for ( i = K - 1; l != 0; i++){
		k += ( S[i] == 40) ? 1 : -1;
		l = (k == 0) ? 0 : l; 
	}
}else{
	for ( i = K -1; l != 0; i--){
		k += ( S[i] == 40) ? 1 : -1;
		l = (k == 0) ? 0 : l;
	}
	i+= 2;
}
printf ("%d",i);
	return 0;
}
0