結果

問題 No.22 括弧の対応
ユーザー history_Basshistory_Bass
提出日時 2017-03-03 13:18:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 3,388 ms
コンパイル使用メモリ 75,736 KB
実行使用メモリ 56,392 KB
最終ジャッジ日時 2023-09-27 13:12:22
合計ジャッジ時間 6,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
56,084 KB
testcase_01 AC 104 ms
55,948 KB
testcase_02 AC 106 ms
54,452 KB
testcase_03 AC 158 ms
56,284 KB
testcase_04 AC 141 ms
56,184 KB
testcase_05 AC 146 ms
55,480 KB
testcase_06 AC 144 ms
56,040 KB
testcase_07 AC 150 ms
56,148 KB
testcase_08 AC 140 ms
55,936 KB
testcase_09 AC 133 ms
56,392 KB
testcase_10 AC 142 ms
55,880 KB
testcase_11 AC 124 ms
55,668 KB
testcase_12 AC 146 ms
55,524 KB
testcase_13 AC 145 ms
56,048 KB
testcase_14 AC 123 ms
55,660 KB
testcase_15 AC 152 ms
56,096 KB
testcase_16 AC 152 ms
55,920 KB
testcase_17 AC 102 ms
56,044 KB
testcase_18 AC 104 ms
55,864 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;
				}
				
			}
		}
			
		System.out.println(i+1);
		
	}
}
0