結果
問題 | No.423 ハムスター語初級(数詞) |
ユーザー | YamaKasa |
提出日時 | 2018-05-23 22:55:26 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 130 ms / 2,000 ms |
コード長 | 858 bytes |
コンパイル時間 | 3,682 ms |
コンパイル使用メモリ | 77,756 KB |
実行使用メモリ | 41,240 KB |
最終ジャッジ日時 | 2024-06-28 16:32:29 |
合計ジャッジ時間 | 5,682 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
import java.util.Scanner; public class MAin { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String n = scan.next(); scan.close(); StringBuilder sb = new StringBuilder(); int l = 0; for(int i = 0; i < n.length(); i++) { char c = n.charAt(i); if(c == 'h') { if(l == 2) { sb.append(0); }else if(l == 3) { sb.append(1); } l = 0; }else { l ++; } if(i == n.length() - 1) { if(l == 2) { sb.append(0); }else if(l == 3) { sb.append(1); } } } int val = Integer.parseInt(sb.toString(), 2); val = val * 2; String ans = Integer.toBinaryString(val); for(int i = 0; i < ans.length(); i++) { char c = ans.charAt(i); if(c == '1') { System.out.print("hamu"); }else { System.out.print("ham"); } } System.out.println(); } }