結果

問題 No.22 括弧の対応
ユーザー history_Basshistory_Bass
提出日時 2017-03-03 13:06:34
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,087 bytes
コンパイル時間 4,831 ms
コンパイル使用メモリ 74,312 KB
実行使用メモリ 56,072 KB
最終ジャッジ日時 2023-09-04 05:19:34
合計ジャッジ時間 7,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 125 ms
55,532 KB
testcase_02 AC 126 ms
55,236 KB
testcase_03 AC 178 ms
55,552 KB
testcase_04 AC 170 ms
55,888 KB
testcase_05 AC 173 ms
55,744 KB
testcase_06 AC 176 ms
55,556 KB
testcase_07 AC 180 ms
55,600 KB
testcase_08 AC 171 ms
55,932 KB
testcase_09 AC 174 ms
55,548 KB
testcase_10 AC 180 ms
55,904 KB
testcase_11 AC 147 ms
55,824 KB
testcase_12 AC 176 ms
55,564 KB
testcase_13 AC 177 ms
55,776 KB
testcase_14 AC 138 ms
53,728 KB
testcase_15 AC 176 ms
55,820 KB
testcase_16 AC 176 ms
55,604 KB
testcase_17 AC 123 ms
55,560 KB
testcase_18 AC 123 ms
56,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class arc {
	public static void main(String args[]){
		
		//文字の読み込み
		Scanner sc=new Scanner(System.in);
		String line1=sc.nextLine();
		String line2=sc.nextLine();
		//文字の分割
		String[] ch1=line1.split(" ",0);//ch1[0]=the amount ch1[1]=question
		String[] ch2=line2.split("",0);//arcs
		
		int judge=0;
		int i=Integer.parseInt(ch1[1]);//=Integer.parseInt(ch1[1]);//この括弧のついの括弧の番号を求める
		int j=Integer.parseInt(ch1[0]);//括弧の総数
		if(ch2[i-1].equals("(")){
			for(i=i-1;i<j;i++){
		
				switch(ch2[i]){
					case "(": 
						judge++;
						break;
					case ")": 
						judge--;
						break;
				}
				
				if(judge==0){
					break;
				}
				
				if(i==(j-1)){
					i=-1;
				}
			}
		}else if(ch2[i-1].equals(")")){
			for(i=i-1;i<j;i--){
				
				switch(ch2[i]){
					case "(": 
						judge++;
						break;
					case ")": 
						judge--;
						break;
				}
				
				if(judge==0){
					break;
				}
				
				if(i==(j-1)){
					i=-1;
				}
			}
		}
			

		System.out.println(i+1);
		
	}
}
0