結果
問題 | No.112 ややこしい鶴亀算 |
ユーザー |
|
提出日時 | 2017-06-08 18:39:38 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,210 bytes |
コンパイル時間 | 3,495 ms |
コンパイル使用メモリ | 78,508 KB |
実行使用メモリ | 54,940 KB |
最終ジャッジ日時 | 2024-09-22 13:33:56 |
合計ジャッジ時間 | 6,297 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 81 ms
51,460 KB |
testcase_01 | AC | 80 ms
51,300 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
ソースコード
package test_5; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * No.112 ややこしい鶴亀算 http://yukicoder.me/problems/no/112 * N 匹の動物がいる。 * 動物たちは 1 から N まで番号が振られている。 * また、動物たちはそれぞれ鶴か亀のいずれかである。 * ご存知の通り、鶴の足は 2 本、亀の足は 4 本である。 */ public class Question_15_0608_2 { static final int MIN = 2; static final int MAX = 50; public static void main(String[] args) { InputStreamReader re = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(re); try { int animalCount = Integer.parseInt(br.readLine()); String[] legStrList = br.readLine().split(" "); //有効値判定 if (NumJudg(animalCount, MIN, MAX)) { //足の合計を求める int legSum = 0; for (int i = 0; i < legStrList.length; i++) { legSum += Integer.parseInt(legStrList[i]); } //全て亀だと仮定し、鶴の数を求める //(匹数の合計×4-実際の足の数)÷2=つるの匹数 int Crane = (animalCount * 4 - legSum) / 2; int turtle = animalCount - Crane; //自分自身の足を数え忘れてしまっているので実際は逆 // 鶴←亀の数 亀←鶴の数 System.out.println(turtle + " " + Crane); } 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; } }