結果

問題 No.112 ややこしい鶴亀算
ユーザー nihi9119nihi9119
提出日時 2017-06-08 18:53:44
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,971 bytes
コンパイル時間 3,431 ms
コンパイル使用メモリ 80,484 KB
実行使用メモリ 56,240 KB
最終ジャッジ日時 2023-10-23 19:52:43
合計ジャッジ時間 6,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
54,504 KB
testcase_01 AC 79 ms
54,484 KB
testcase_02 AC 90 ms
54,684 KB
testcase_03 AC 81 ms
52,904 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 81 ms
54,492 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 80 ms
54,516 KB
testcase_11 AC 79 ms
54,404 KB
testcase_12 AC 79 ms
54,584 KB
testcase_13 WA -
testcase_14 AC 81 ms
54,620 KB
testcase_15 WA -
testcase_16 AC 80 ms
54,660 KB
testcase_17 WA -
testcase_18 AC 84 ms
54,628 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 89 ms
54,624 KB
testcase_22 AC 78 ms
54,500 KB
testcase_23 AC 79 ms
54,760 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 Crane = 0;
				int turtle = 0;

				//足から求める
				for (int i = 0; i < legStrList.length; i++) {
					int num = Integer.parseInt(legStrList[i]);
					if (num % 4 == 0) {
						Crane++;
					} else {
						turtle++;
					}
				}
				System.out.println(Crane + " " + turtle);
			} 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;
	}

}
0