結果

問題 No.22 括弧の対応
ユーザー sasa
提出日時 2025-03-05 11:34:58
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 438 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 25,088 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2025-03-05 11:35:00
合計ジャッジ時間 1,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d %d",&len,&val);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
main.c:10:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%c",&p[i]);
      |                 ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	int len, val;
	scanf("%d %d",&len,&val);
	char str[len];
	char *p = str;
	
	for(int i = 0;i < len;i++){
		scanf("%c",&p[i]);
	}
	
	int count = 0;
	for(int i = val;i < len;i++){
		if(p[i] == '('){
			count++;
		}else{
			count--;
		}
		//printf("int:%d count:%d str:%c\n",i,count,p[i]);
		if(count == 0){
			printf("%d",i);
			break;
		}else if(count != 0 && i == (len - 1)){
			printf("0");
		}
	}
}
0