結果
| 問題 |
No.279 木の数え上げ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-31 18:03:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 524 ms / 2,000 ms |
| コード長 | 2,269 bytes |
| コンパイル時間 | 5,156 ms |
| コンパイル使用メモリ | 76,024 KB |
| 実行使用メモリ | 49,004 KB |
| 最終ジャッジ日時 | 2024-09-26 13:49:54 |
| 合計ジャッジ時間 | 11,160 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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;
}
}