結果

問題 No.69 文字を自由に並び替え
ユーザー ohagi_1182
提出日時 2017-10-21 10:12:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 915 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 84,776 KB
実行使用メモリ 54,364 KB
最終ジャッジ日時 2024-12-14 06:46:50
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

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