結果

問題 No.587 七対子
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 23:22:24
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 73,316 KB
実行使用メモリ 57,824 KB
最終ジャッジ日時 2023-08-13 16:24:31
合計ジャッジ時間 7,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,256 KB
testcase_01 AC 116 ms
55,752 KB
testcase_02 AC 116 ms
55,936 KB
testcase_03 AC 116 ms
55,252 KB
testcase_04 AC 114 ms
55,068 KB
testcase_05 AC 116 ms
55,928 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 115 ms
55,956 KB
testcase_10 AC 115 ms
55,380 KB
testcase_11 WA -
testcase_12 AC 114 ms
55,608 KB
testcase_13 AC 115 ms
56,040 KB
testcase_14 AC 114 ms
55,944 KB
testcase_15 AC 114 ms
55,368 KB
testcase_16 WA -
testcase_17 AC 114 ms
55,380 KB
testcase_18 AC 114 ms
55,908 KB
testcase_19 AC 114 ms
55,868 KB
testcase_20 WA -
testcase_21 AC 114 ms
55,756 KB
testcase_22 AC 113 ms
55,388 KB
testcase_23 AC 113 ms
53,660 KB
testcase_24 AC 114 ms
55,796 KB
testcase_25 AC 118 ms
55,744 KB
testcase_26 AC 114 ms
56,000 KB
testcase_27 AC 113 ms
55,064 KB
testcase_28 WA -
testcase_29 AC 113 ms
55,372 KB
testcase_30 AC 114 ms
55,664 KB
testcase_31 AC 114 ms
55,640 KB
testcase_32 AC 114 ms
55,924 KB
testcase_33 AC 113 ms
55,996 KB
testcase_34 AC 113 ms
55,776 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