結果
| 問題 |
No.69 文字を自由に並び替え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-16 18:38:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 59 ms / 5,000 ms |
| コード長 | 2,565 bytes |
| コンパイル時間 | 3,701 ms |
| コンパイル使用メモリ | 78,064 KB |
| 実行使用メモリ | 50,540 KB |
| 最終ジャッジ日時 | 2024-12-14 06:39:31 |
| 合計ジャッジ時間 | 5,250 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
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;
}
}