結果

問題 No.1894 Delete AB
ユーザー masayamatumasayamatu
提出日時 2022-06-25 15:01:24
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 1,531 bytes
コンパイル時間 12,266 ms
コンパイル使用メモリ 166,732 KB
実行使用メモリ 208,436 KB
最終ジャッジ日時 2024-04-26 21:33:13
合計ジャッジ時間 15,303 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 165 ms
52,992 KB
testcase_14 AC 163 ms
208,436 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (100 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
//using static CompLib.CompLib;
//using DataStructure;

namespace atcoder
{
    class Program
    {
        const int intMax = 1000000000;
        const long longMax = 2000000000000000000;
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            while (T-- > 0)
            {
                int N = int.Parse(Console.ReadLine());
                String S = Console.ReadLine();
                var stack = new Stack<char>();
                for (int i = S.Length - 1; i >= 0; i--)
                {
                    stack.Push(S[i]);
                    if (stack.Count > 2)
                    {
                        if (stack.ElementAt(1) == 'B' && stack.ElementAt(0) == 'A' && stack.ElementAt(2) == 'B')
                        {
                            stack.Pop();
                            stack.Pop();
                        }
                    }
                    else if (stack.Count == 2 && stack.ElementAt(1) == 'B' && stack.ElementAt(0) == 'A' && i >= 2)
                    {
                        stack.Pop();
                        stack.Pop();
                    }
                }
                String ans = "";
                while (stack.Count > 0)
                {
                    ans += stack.Pop();
                }
                Console.WriteLine(ans);
            }
        }
    }
}
0