結果

問題 No.559 swapAB列
ユーザー RisenRisen
提出日時 2017-08-25 22:30:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 113,728 KB
実行使用メモリ 26,796 KB
最終ジャッジ日時 2024-04-23 15:34:23
合計ジャッジ時間 1,493 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
26,796 KB
testcase_01 AC 29 ms
26,520 KB
testcase_02 AC 26 ms
26,668 KB
testcase_03 AC 26 ms
24,860 KB
testcase_04 AC 26 ms
24,728 KB
testcase_05 AC 25 ms
24,748 KB
testcase_06 AC 25 ms
24,728 KB
testcase_07 AC 26 ms
24,880 KB
testcase_08 AC 25 ms
24,860 KB
testcase_09 AC 25 ms
24,604 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static Common;

public static class Common
{
    public static void Swap<T>(ref T lhs, ref T rhs)
    {
        T temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
}
class Solution
{
    static void Main()
    {
        var s = Console.ReadLine().ToArray();
        var aCount = s.Count(c => c == 'A');
        int count = 0;

        while (!s.Take(aCount).All(c => c == 'A'))
        {
            var target = 0;
            for (; true; target++)
            {
                if (s[target] == 'B' && s[target + 1] == 'A')
                {
                    break;
                }
            }

            Swap(ref s[target], ref s[target + 1]);
            count++;
        }

        Console.WriteLine(count);
    }
}
0