結果
問題 | No.587 七対子 |
ユーザー |
![]() |
提出日時 | 2019-02-21 23:22:24 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 957 bytes |
コンパイル時間 | 2,041 ms |
コンパイル使用メモリ | 77,772 KB |
実行使用メモリ | 55,868 KB |
最終ジャッジ日時 | 2024-11-21 12:26:44 |
合計ジャッジ時間 | 7,422 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 WA * 7 |
ソースコード
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; } }