結果

問題 No.279 木の数え上げ
ユーザー jimanojimano
提出日時 2016-07-18 15:18:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,287 bytes
コンパイル時間 5,011 ms
コンパイル使用メモリ 79,236 KB
実行使用メモリ 58,192 KB
最終ジャッジ日時 2024-04-23 16:25:33
合計ジャッジ時間 7,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class No0279 {
	public static void main(String[] args) {
		try (BufferedReader br = 
				new BufferedReader(new InputStreamReader(System.in))) {
			char[] arr = br.readLine().toCharArray();
			Map<Character, Integer> m = new HashMap<>();
			Arrays.sort(arr);
			
			for (char c : arr) {
				if (isLetter(c)) {
					if (m.containsKey(c)) {
						int cnt = m.get(c);
						m.put(c, ++cnt);
					} else {
						m.put(c, 1);
					}
				}
			}
			System.out.println(m);
			int t_cnt = m.get('t');
			int r_cnt = m.get('r');
			int e_cnt = m.get('e');
			int tree_cnt = 0;
			if (isOverZero(t_cnt, r_cnt, e_cnt)) {
				// t r 小さいほうと比べてeが何個分とれる?
				if (t_cnt >= r_cnt) {
					tree_cnt += (e_cnt / (r_cnt * 2) * r_cnt);
				} else {
					tree_cnt += (e_cnt / (t_cnt * 2) * t_cnt);
				}
			}
			System.out.println(tree_cnt);
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
	
	static boolean isLetter(char c){
		return (c == 't' || c == 'r' || c == 'e');
	}
	
	static boolean isOverZero(int t_cnt, int r_cnt, int e_cnt){
		return t_cnt > 0 && r_cnt > 0 && e_cnt > 0;
	}
	
}
0