結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2016-09-08 14:43:39 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,228 bytes |
コンパイル時間 | 3,405 ms |
コンパイル使用メモリ | 77,972 KB |
実行使用メモリ | 41,776 KB |
最終ジャッジ日時 | 2024-11-15 22:17:52 |
合計ジャッジ時間 | 7,024 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 RE * 1 |
ソースコード
import java.util.*; public class Run { public static void main (String arg[]) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt() - 1; if (N < 1||N > 10000||K < 1||K > N) System.exit(1); String S = scan.next(); if (S.length()!=N) System.exit(1); boolean flag; if (S.charAt(K)=='(') flag = true; else flag = false; Stack stackS = new Stack(); int count = 0; if (flag) { while (true) { if (S.charAt(K) == '(') { stackS.push(S.charAt(K)); count++; } else { stackS.pop(); count--; if (count==0) break; } K++; } } else { while (true) { if (S.charAt(K) == ')') { stackS.push(S.charAt(K)); count++; } else { stackS.pop(); count--; if (count == 0) break; } K--; } } System.out.println(K+1); } }