結果

問題 No.22 括弧の対応
ユーザー history_Bass
提出日時 2017-03-03 01:22:14
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 768 bytes
コンパイル時間 3,342 ms
コンパイル使用メモリ 74,512 KB
実行使用メモリ 61,204 KB
最終ジャッジ日時 2024-06-13 02:11:12
合計ジャッジ時間 16,273 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

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 i,judge=0,count=0,answer=0;
		i=Integer.parseInt(ch1[1]);//この括弧のついの括弧の番号を求める
		int j=Integer.parseInt(ch1[0]);//括弧の総数
		i--;
		do{
			
			switch(ch2[i]){
				case "(": judge++;
				case ")": judge--;
			}
			
			if(judge==0){
				answer=i+1;
				break;
			}
			
			if(i==(j-1)){
				i=0;
			}else{
				i++;
			}
			
		}while(i<j);
		
		System.out.println(answer);
		
	}
}
0