結果
| 問題 |
No.279 木の数え上げ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-31 18:31:12 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 149 ms / 2,000 ms |
| コード長 | 2,373 bytes |
| コンパイル時間 | 3,260 ms |
| コンパイル使用メモリ | 76,576 KB |
| 実行使用メモリ | 43,580 KB |
| 最終ジャッジ日時 | 2024-09-21 20:26:08 |
| 合計ジャッジ時間 | 6,672 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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"という
* 部分文字列をいくつ作ることが可能か興味があります。
* 教えてあげてください。
*
* 40分
*/
public class Question_09_0531 {
static final int LENGTH_MIN = 1;
static final int LENGTH_MAX = (int)Math.pow(10, 6);
static final char KEY_T = 't';
static final char KEY_R = 'r';
static final char 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 = 0;
int cntR = 0;
int cntE = 0;
for (char c : kamipeipaa.toCharArray()){
if(c == KEY_T){
cntT++;
}
if(c == KEY_R){
cntR++;
}
if(c == KEY_E){
cntE++;
}
}
int cntECount = cntE / 2;
if (cntT >= 1 && cntR >= 1 && cntECount >= 1) {
//最小値取得
int min = 0;
min = Math.min(cntT, cntR);
min = Math.min(min, cntECount);
treeCount = min;
} else {
treeCount = 0;
}
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;
}
}