結果

問題 No.1894 Delete AB
ユーザー tenten
提出日時 2022-09-27 13:08:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,757 bytes
コンパイル時間 2,722 ms
コンパイル使用メモリ 78,592 KB
実行使用メモリ 44,980 KB
最終ジャッジ日時 2024-12-22 16:47:11
合計ジャッジ時間 6,219 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
ArrayDeque<Character> deq = new ArrayDeque<>();
while (n-- > 0) {
int x = sc.nextInt();
char[] arr = sc.next().toCharArray();
for (int i = x - 1; i >= 0; i--) {
if (arr[i] == 'A' && deq.size() >= 2) {
char p = deq.pop();
if (p == 'B' && deq.peek() == 'B') {
} else {
deq.push(p);
deq.push('A');
}
} else {
deq.push(arr[i]);
}
}
while (deq.size() > 0) {
sb.append(deq.pop());
}
sb.append("\n");
}
System.out.print(sb);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0