結果

問題 No.587 七対子
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 23:22:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 77,500 KB
実行使用メモリ 54,576 KB
最終ジャッジ日時 2024-05-01 09:11:11
合計ジャッジ時間 8,009 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,200 KB
testcase_01 AC 123 ms
54,136 KB
testcase_02 AC 141 ms
53,908 KB
testcase_03 AC 127 ms
54,224 KB
testcase_04 AC 110 ms
52,680 KB
testcase_05 AC 125 ms
54,264 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 124 ms
54,004 KB
testcase_10 AC 146 ms
54,072 KB
testcase_11 WA -
testcase_12 AC 125 ms
54,204 KB
testcase_13 AC 123 ms
54,136 KB
testcase_14 AC 128 ms
53,968 KB
testcase_15 AC 125 ms
54,188 KB
testcase_16 WA -
testcase_17 AC 124 ms
54,220 KB
testcase_18 AC 124 ms
54,072 KB
testcase_19 AC 127 ms
54,112 KB
testcase_20 WA -
testcase_21 AC 124 ms
54,220 KB
testcase_22 AC 124 ms
54,088 KB
testcase_23 AC 125 ms
54,348 KB
testcase_24 AC 124 ms
54,152 KB
testcase_25 AC 123 ms
54,076 KB
testcase_26 AC 127 ms
53,812 KB
testcase_27 AC 125 ms
54,076 KB
testcase_28 WA -
testcase_29 AC 110 ms
52,944 KB
testcase_30 AC 123 ms
54,100 KB
testcase_31 AC 111 ms
52,896 KB
testcase_32 AC 121 ms
54,188 KB
testcase_33 AC 126 ms
54,308 KB
testcase_34 AC 140 ms
54,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static final int IMPOSSIBLE = -1;

	static public void main(String[]args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		solve(s);
	}

	static void solve(String s) throws Exception {
		int [] alphabet = new int[26];
		for(int i=0; i<s.length(); i++) {
			int tmp = s.charAt(i) - 'a';
			alphabet[tmp]++;
		}

		int ans = searchAns(alphabet);
		if(ans == IMPOSSIBLE) {
			System.out.println("Impossible");
		} else {
			System.out.println( (char)('a' + ans) );
		}
	}

	static int searchAns(int [] alphabet) throws Exception {
		final int NUM_ALPHABET = 26;
		int count = IMPOSSIBLE;
		for(int i=0; i < NUM_ALPHABET; i++) {
			if(alphabet[i] == 0 || alphabet[i] == 2) {
				//nothing
			} else if(alphabet[i] == 1) {
				if(count  == IMPOSSIBLE) {
					count = i;
				} else {
					count = IMPOSSIBLE;
					break;
				}
			} else {
				break;
			}
		}
		return count;
	}
}
0