結果

問題 No.197 手品
ユーザー kenkoooo
提出日時 2015-04-28 23:52:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 138 ms / 1,000 ms
コード長 1,581 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 77,644 KB
実行使用メモリ 41,456 KB
最終ジャッジ日時 2024-07-20 03:34:33
合計ジャッジ時間 9,893 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String before = sc.next();
		int N = sc.nextInt();
		String after = sc.next();
		sc.close();

		int bCoins = 0;
		int aCoins = 0;
		for (int i = 0; i < 3; i++) {
			if (before.charAt(i) == 'o') {
				bCoins++;
			}
			if (after.charAt(i) == 'o') {
				aCoins++;
			}
		}

		if (aCoins == 1) {
			before = before.replaceAll("o", "1").replaceAll("x", "2");
			after = after.replaceAll("o", "1").replaceAll("x", "2");
		} else {
			before = before.replaceAll("o", "2").replaceAll("x", "1");
			after = after.replaceAll("o", "2").replaceAll("x", "1");
		}
		if (aCoins != bCoins) {
			System.out.println("SUCCESS");
			return;
		}

		if (aCoins == 0 || aCoins == 3) {
			System.out.println("FAILURE");
			return;
		}

		if (before.equals("122") || before.equals("221")) {
			if (before.equals(after)) {
				System.out.println("FAILURE");
				return;
			} else if (after.equals("212")) {
				if (N >= 1) {
					System.out.println("FAILURE");
					return;
				}
				System.out.println("SUCCESS");
				return;
			} else {
				if (N >= 2) {
					System.out.println("FAILURE");
					return;
				}
				System.out.println("SUCCESS");
				return;

			}
		} else {
			if (before.equals(after)) {
				if (N == 1) {
					System.out.println("SUCCESS");
					return;
				}
				System.out.println("FAILURE");
				return;
			} else {
				if (N == 0) {
					System.out.println("SUCCESS");
					return;
				}
				System.out.println("FAILURE");
				return;
			}
		}

	}

}
0