結果

問題 No.279 木の数え上げ
ユーザー nihi9119nihi9119
提出日時 2017-05-31 18:03:06
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,269 bytes
コンパイル時間 3,432 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 64,692 KB
最終ジャッジ日時 2023-11-30 06:52:22
合計ジャッジ時間 10,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
54,792 KB
testcase_01 AC 64 ms
54,384 KB
testcase_02 AC 71 ms
54,764 KB
testcase_03 AC 67 ms
54,392 KB
testcase_04 AC 60 ms
54,268 KB
testcase_05 AC 69 ms
54,756 KB
testcase_06 AC 64 ms
54,380 KB
testcase_07 AC 63 ms
54,248 KB
testcase_08 AC 82 ms
55,416 KB
testcase_09 AC 62 ms
54,256 KB
testcase_10 AC 467 ms
62,316 KB
testcase_11 AC 219 ms
57,804 KB
testcase_12 AC 425 ms
60,956 KB
testcase_13 AC 199 ms
57,400 KB
testcase_14 AC 479 ms
63,280 KB
testcase_15 AC 467 ms
62,292 KB
testcase_16 AC 446 ms
60,896 KB
testcase_17 AC 468 ms
62,696 KB
testcase_18 AC 371 ms
60,532 KB
testcase_19 AC 479 ms
62,292 KB
testcase_20 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package test_5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * No.279 木の数え上げ
 * kamipeipaa君は木が大好きですが,今日は文字列で遊んでいます。
 * kamipeipaa君は文字列SSを並び替えたときに"tree"という
 * 部分文字列をいくつ作ることが可能か興味があります。
 * 教えてあげてください。
 */

public class Question_09_0531 {

	static final int LENGTH_MIN = 1;
	static final int LENGTH_MAX = (int)Math.pow(10, 6);
	static final String KEY_T = "t";
	static final String KEY_R = "r";
	static final String KEY_E = "e";

	public static void main(String[] args) {

		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			String kamipeipaa = br.readLine();
			if (LengthJudg(kamipeipaa, LENGTH_MIN, LENGTH_MAX)) {

				int treeCount = 0;

				//それぞれの文字の個数を調べる("t","r","e")
				int cntT = kamipeipaa.replaceAll("[^" + KEY_T + "]", "").length();
				int cntR = kamipeipaa.replaceAll("[^" + KEY_R + "]", "").length();
				int cntE = kamipeipaa.replaceAll("[^" + KEY_E + "]", "").length();

				while(true) {
					if (cntT >= 1 && cntR >= 1 && cntE >= 2) {
						treeCount++;
						cntT--;
						cntR--;
						cntE = cntE - 2;
					} else {
						break;
					}
				}

				System.out.println(treeCount);

			} 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 str 判定する文字列
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean LengthJudg(String str, int min, int max) {
		Boolean result = false;
		if (min <= str.length() && str.length() <= max) {
			result = true;
		}
		return result;
	}
}
0