結果

問題 No.197 手品
ユーザー spacia
提出日時 2016-01-04 22:13:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 68 ms / 1,000 ms
コード長 1,080 bytes
コンパイル時間 2,404 ms
コンパイル使用メモリ 77,200 KB
実行使用メモリ 50,372 KB
最終ジャッジ日時 2024-07-20 03:45:12
合計ジャッジ時間 6,362 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static boolean solve (String s , String t , int n) {
		int cnt1 = 0 , cnt2 = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'o') cnt1++;
			if (t.charAt(i) == 'o') cnt2++;
		}
		if (cnt1 != cnt2) return true;
		if (cnt1 == 0 || cnt1 == 3) return false;
		int p1 = -1 , p2 = -1;
		if (cnt1 == 1) {
			p1 = s.indexOf("o");
			p2 = t.indexOf("o");
		} else {
			p1 = s.indexOf("x");
			p2 = t.indexOf("x");
		}
		if (p1 == 1) {
			if (p2 == 1) {
				return n == 1;
			} else {
				return n == 0;
			}
		} else {
			if (p2 == 1) {
				return n == 0;
			} else {
				return p1 == p2 ? false : n < 2;
			}
		}
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		String s = br.readLine();
		int n = Integer.parseInt(br.readLine());
		String t = br.readLine();
		
		out(solve(s , t , n) ? "SUCCESS" : "FAILURE");
		
	}
}
0