結果

問題 No.69 文字を自由に並び替え
ユーザー ohagi_1182ohagi_1182
提出日時 2017-10-21 10:12:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 86,036 KB
実行使用メモリ 55,952 KB
最終ジャッジ日時 2023-08-20 23:50:04
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,724 KB
testcase_01 AC 118 ms
55,376 KB
testcase_02 AC 119 ms
55,896 KB
testcase_03 AC 120 ms
55,404 KB
testcase_04 AC 121 ms
55,860 KB
testcase_05 AC 122 ms
55,952 KB
testcase_06 AC 121 ms
55,880 KB
testcase_07 AC 119 ms
55,824 KB
testcase_08 AC 121 ms
55,828 KB
testcase_09 AC 120 ms
55,372 KB
testcase_10 AC 119 ms
55,512 KB
testcase_11 AC 118 ms
55,424 KB
testcase_12 AC 120 ms
55,828 KB
testcase_13 AC 120 ms
55,780 KB
testcase_14 AC 118 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int n1 = a.length();
		int n2 = b.length();
		if(n1 != n2) {
			System.out.println("NO");
			return;
		}
		Map<String, Integer> map1 = new HashMap<>();
		Map<String, Integer> map2 = new HashMap<>();
		for(char c = 'a' ; c <= 'z' ; c++) {
			map1.put("" + c, 0);
			map2.put("" + c, 0);
		}
		for(int i = 0 ; i < n1 ; i++) {
			map1.put("" + a.charAt(i), map1.get("" + a.charAt(i)) + 1);
			map2.put("" + b.charAt(i), map2.get("" + b.charAt(i)) + 1);
		}
		int cnt = 0;
		for(int i = 0 ; i < n1 ; i++) {
			if(map1.get("" + a.charAt(i)) == map2.get("" + a.charAt(i))) {
				cnt++;
			}
		}
		if(cnt == n1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
 	}
}

0