結果

問題 No.587 七対子
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-21 23:16:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 3,888 ms
コンパイル使用メモリ 71,976 KB
実行使用メモリ 57,520 KB
最終ジャッジ日時 2023-08-13 16:09:38
合計ジャッジ時間 7,943 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,640 KB
testcase_01 AC 116 ms
55,648 KB
testcase_02 AC 116 ms
55,768 KB
testcase_03 AC 117 ms
55,224 KB
testcase_04 AC 117 ms
55,232 KB
testcase_05 AC 119 ms
55,296 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 114 ms
55,900 KB
testcase_10 AC 114 ms
55,656 KB
testcase_11 WA -
testcase_12 AC 116 ms
55,988 KB
testcase_13 AC 116 ms
55,636 KB
testcase_14 AC 115 ms
55,792 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 118 ms
56,016 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 117 ms
55,388 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 117 ms
55,952 KB
testcase_31 WA -
testcase_32 AC 117 ms
55,872 KB
testcase_33 AC 117 ms
55,532 KB
testcase_34 AC 116 ms
55,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	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 == -1) {
			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 = -1;
		for(int i=0; i < NUM_ALPHABET; i++) {
			if(alphabet[i] == 0 || alphabet[i] == 2) {
				//nothing
			} else if(alphabet[i] == 1) {
				if(count  == -1) {
					count = i;
				} else {
					break;
				}
			} else {
				break;
			}
		}
		return count;
	}
}
0