結果
問題 | No.587 七対子 |
ユーザー |
![]() |
提出日時 | 2019-02-21 23:25:45 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 2,561 ms |
コンパイル使用メモリ | 77,484 KB |
実行使用メモリ | 41,244 KB |
最終ジャッジ日時 | 2024-07-19 19:58:28 |
合計ジャッジ時間 | 7,174 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
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; } }