結果
| 問題 |
No.47 ポケットを叩くとビスケットが2倍
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-16 18:19:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 5,000 ms |
| コード長 | 1,529 bytes |
| コンパイル時間 | 2,955 ms |
| コンパイル使用メモリ | 77,792 KB |
| 実行使用メモリ | 51,880 KB |
| 最終ジャッジ日時 | 2024-10-01 06:49:49 |
| 合計ジャッジ時間 | 4,789 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
package test7;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* No.47 ポケットを叩くとビスケットが2倍
* http://yukicoder.me/problems/89
*/
public class Question_21_0616 {
final static int MIN = 1;
final static int MAX = (int)Math.pow(10, 8);
public static void main(String[] args) {
InputStreamReader re = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(re);
try {
int result = Integer.parseInt(br.readLine());
if (NumJudg(result, MIN, MAX)) {
int Biscuits = 1;
int count = 0;
while (Biscuits < result) {
Biscuits = Biscuits * 2;
count++;
}
System.out.println(count);
} else {
System.out.println("文字が有効範囲外です");
}
} catch (NumberFormatException e){
System.out.println("数字を入力して下さい");
} catch (IOException e) {
System.out.println("エラーが発生しました");
} finally {
try {
re.close();
br.close();
} catch (IOException e) {
System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
}
}
}
/**
* 有効値判定
* @param input 判定するもの
* @param max 最大値
* @param min 最小値
* @return 範囲内ならtrue,範囲外ならfalseを返す
*/
private static boolean NumJudg(int input, int min, int max) {
Boolean result = false;
if (min <= input && input <= max) {
result = true;
}
return result;
}
}