結果

問題 No.22 括弧の対応
ユーザー kohaku_kohaku
提出日時 2016-11-14 01:33:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 766 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 74,888 KB
実行使用メモリ 42,540 KB
最終ジャッジ日時 2024-07-20 07:18:03
合計ジャッジ時間 7,112 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();
        String [] arr = S.split("");
        int a=0;
        if( arr[K-1].equals(")") ){
            while(a!=-1){
                K--;
                if( arr[K-1].equals(")") ){
                    a++;
                }else{
                    a--;
                }
            }
        }else{
            while(a!=-1){
                K++;
                if( arr[K-1].equals("(") ){
                    a++;
                }else{
                    a--;
                }
            }
        }
        System.out.println(K);
    }
}
0