結果

問題 No.69 文字を自由に並び替え
ユーザー nihi9119nihi9119
提出日時 2017-06-16 18:38:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 2,565 bytes
コンパイル時間 3,558 ms
コンパイル使用メモリ 74,520 KB
実行使用メモリ 34,096 KB
最終ジャッジ日時 2023-08-20 23:42:31
合計ジャッジ時間 5,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
33,672 KB
testcase_01 AC 40 ms
34,096 KB
testcase_02 AC 40 ms
33,720 KB
testcase_03 AC 40 ms
33,600 KB
testcase_04 AC 39 ms
33,668 KB
testcase_05 AC 43 ms
33,664 KB
testcase_06 AC 40 ms
33,596 KB
testcase_07 AC 39 ms
33,608 KB
testcase_08 AC 39 ms
33,664 KB
testcase_09 AC 40 ms
33,764 KB
testcase_10 AC 39 ms
33,712 KB
testcase_11 AC 39 ms
33,668 KB
testcase_12 AC 39 ms
33,596 KB
testcase_13 AC 40 ms
33,600 KB
testcase_14 AC 43 ms
33,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test7;

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

/**
 * No.69 文字を自由に並び替え
 * http://yukicoder.me/problems/35
 */

public class Question_22_0616 {

	final static int MIN = 1;
	final static int MAX = 10;
	static HashMap<String, Integer> inputMap1 = new HashMap<String, Integer>();
	static HashMap<String, Integer> inputMap2 = new HashMap<String, Integer>();

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			String[] inputstr1 = br.readLine().split("");
			String[] inputstr2 = br.readLine().split("");

			//文字の長さ確認
			if (NumJudg(inputstr1.length, MIN, MAX)) {
				//inputstr1文字数を数える
				int count = 0;
				for (int i = 0; i < inputstr1.length; i++) {
					if (inputMap1.containsKey(inputstr1[i])) {
						// Mapに登録済み
						count = inputMap1.get(inputstr1[i]) + 1;
					} else {
						// Mapに未登録
						count = 1;
					}
					inputMap1.put(inputstr1[i], count);
				}

				//inputstr2文字数を数える
				for (int i = 0; i < inputstr2.length; i++) {
					if (inputMap2.containsKey(inputstr2[i])) {
						// Mapに登録済み
						count = inputMap2.get(inputstr2[i]) + 1;
					} else {
						// Mapに未登録
						count = 1;
					}
					inputMap2.put(inputstr2[i], count);
				}

				//文字数を確かめる
				boolean flg = true;
				for (String str : inputMap1.keySet()) {
					if (inputMap1.get(str) != inputMap2.get(str)) {
						flg = false;
						break;
					}
				}

				if (flg) {
					System.out.println("YES");
				} else {
					System.out.println("NO");
				}
			} 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