結果

問題 No.587 七対子
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 23:25:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 4,859 ms
コンパイル使用メモリ 78,492 KB
実行使用メモリ 56,036 KB
最終ジャッジ日時 2023-09-27 02:28:47
合計ジャッジ時間 10,786 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,836 KB
testcase_01 AC 124 ms
55,648 KB
testcase_02 AC 124 ms
55,616 KB
testcase_03 AC 125 ms
55,360 KB
testcase_04 AC 125 ms
53,756 KB
testcase_05 AC 123 ms
55,648 KB
testcase_06 AC 125 ms
55,716 KB
testcase_07 AC 118 ms
55,768 KB
testcase_08 AC 118 ms
55,708 KB
testcase_09 AC 119 ms
55,904 KB
testcase_10 AC 118 ms
55,320 KB
testcase_11 AC 118 ms
55,572 KB
testcase_12 AC 117 ms
55,608 KB
testcase_13 AC 123 ms
55,652 KB
testcase_14 AC 139 ms
55,384 KB
testcase_15 AC 137 ms
55,576 KB
testcase_16 AC 141 ms
55,680 KB
testcase_17 AC 140 ms
55,620 KB
testcase_18 AC 137 ms
55,560 KB
testcase_19 AC 125 ms
55,808 KB
testcase_20 AC 119 ms
55,352 KB
testcase_21 AC 122 ms
55,388 KB
testcase_22 AC 119 ms
55,716 KB
testcase_23 AC 119 ms
55,708 KB
testcase_24 AC 117 ms
55,632 KB
testcase_25 AC 117 ms
55,804 KB
testcase_26 AC 119 ms
55,600 KB
testcase_27 AC 120 ms
55,360 KB
testcase_28 AC 119 ms
55,696 KB
testcase_29 AC 117 ms
55,704 KB
testcase_30 AC 119 ms
53,752 KB
testcase_31 AC 117 ms
55,700 KB
testcase_32 AC 118 ms
55,912 KB
testcase_33 AC 122 ms
55,588 KB
testcase_34 AC 119 ms
56,036 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 answer = IMPOSSIBLE;
		for(int i=0; i < NUM_ALPHABET; i++) {
			if(alphabet[i] == 0 || alphabet[i] == 2) {
				//nothing
			} else if(alphabet[i] == 1) {
				if(answer  == IMPOSSIBLE) {
					answer = i;
				} else {
					return IMPOSSIBLE;
				}
			} else {
				return IMPOSSIBLE;
			}
		}
		return answer;
	}
}
0