結果

問題 No.197 手品
ユーザー mobius_bkstmobius_bkst
提出日時 2015-04-29 13:34:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 42 ms / 1,000 ms
コード長 1,753 bytes
コンパイル時間 3,542 ms
コンパイル使用メモリ 80,976 KB
実行使用メモリ 49,516 KB
最終ジャッジ日時 2023-09-27 09:28:22
合計ジャッジ時間 6,329 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,448 KB
testcase_01 AC 39 ms
49,444 KB
testcase_02 AC 42 ms
49,244 KB
testcase_03 AC 40 ms
49,124 KB
testcase_04 AC 38 ms
49,176 KB
testcase_05 AC 39 ms
47,500 KB
testcase_06 AC 40 ms
49,228 KB
testcase_07 AC 40 ms
49,396 KB
testcase_08 AC 40 ms
49,108 KB
testcase_09 AC 39 ms
49,376 KB
testcase_10 AC 38 ms
49,256 KB
testcase_11 AC 38 ms
49,384 KB
testcase_12 AC 38 ms
49,456 KB
testcase_13 AC 37 ms
49,136 KB
testcase_14 AC 38 ms
49,424 KB
testcase_15 AC 38 ms
49,084 KB
testcase_16 AC 38 ms
49,208 KB
testcase_17 AC 39 ms
49,040 KB
testcase_18 AC 38 ms
49,320 KB
testcase_19 AC 40 ms
49,316 KB
testcase_20 AC 39 ms
49,112 KB
testcase_21 AC 39 ms
46,988 KB
testcase_22 AC 41 ms
49,148 KB
testcase_23 AC 39 ms
49,180 KB
testcase_24 AC 40 ms
47,532 KB
testcase_25 AC 39 ms
47,760 KB
testcase_26 AC 39 ms
49,216 KB
testcase_27 AC 39 ms
49,144 KB
testcase_28 AC 40 ms
49,464 KB
testcase_29 AC 39 ms
49,428 KB
testcase_30 AC 40 ms
49,172 KB
testcase_31 AC 41 ms
49,316 KB
testcase_32 AC 39 ms
49,220 KB
testcase_33 AC 39 ms
49,396 KB
testcase_34 AC 38 ms
49,516 KB
testcase_35 AC 41 ms
49,208 KB
testcase_36 AC 38 ms
49,264 KB
testcase_37 AC 40 ms
49,204 KB
testcase_38 AC 40 ms
47,100 KB
testcase_39 AC 39 ms
49,200 KB
testcase_40 AC 41 ms
47,616 KB
testcase_41 AC 39 ms
49,364 KB
testcase_42 AC 40 ms
49,232 KB
testcase_43 AC 39 ms
49,116 KB
testcase_44 AC 37 ms
49,164 KB
testcase_45 AC 39 ms
49,284 KB
testcase_46 AC 39 ms
49,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class No197 {

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            String SBefore = br.readLine();
            int N = Integer.parseInt(br.readLine());
            String SAfter = br.readLine();

            // コインの枚数を数える
            int bCoin = 0;
            int aCoin = 0;
            for (int i = 0; i < 3; i++) {
                if (SBefore.substring(i, i + 1).equals("o")) {
                    bCoin++;
                }
                if (SAfter.substring(i, i + 1).equals("o")) {
                    aCoin++;
                }
            }

            String str = "FAILURE";
            if (aCoin != bCoin) {
                str = "SUCCESS";
            } else {

                if (N == 0 && !SBefore.equals(SAfter)) {
                    str = "SUCCESS";
                } else if (N == 1) {
                    if (!swap(SBefore, true).equals(SAfter)
                            && !swap(SBefore, false).equals(SAfter)) {
                        str = "SUCCESS";
                    }
                }

            }
            System.out.println(str);
        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    // trueなら左
    // falseなら右
    static String swap(String S, boolean changeSide) {
        char[] c = S.toCharArray();
        char swap = c[1];
        if (changeSide) {
            c[1] = c[0];
            c[0] = swap;
        } else {
            c[1] = c[2];
            c[2] = swap;
        }

        return new String(c);

    }

}
0