結果

問題 No.69 文字を自由に並び替え
ユーザー muston
提出日時 2016-06-01 09:06:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 5,000 ms
コード長 850 bytes
コンパイル時間 3,512 ms
コンパイル使用メモリ 75,152 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2024-12-14 06:15:36
合計ジャッジ時間 6,241 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
/*No.69*/
public class No69 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//文字列Aを入力
		char[] a = scan.next().toCharArray();
		//文字列Bを入力
		char[] b = scan.next().toCharArray();
		//配列を文字コードに変換
		int[] aCord = new int[a.length];
		int[] bCord = new int[b.length];
		boolean canSwap = true;
		for(int i=0;i<a.length;i++){
			 aCord[i] = (int)a[i];
			 bCord[i] = (int)b[i];
		}
		//AとBを並び替え
		Arrays.sort(aCord);
		Arrays.sort(bCord);
		//一文字ずつ比較
		for(int i=0;i<aCord.length;i++){
			if(aCord[i]!=bCord[i]){
				canSwap = false;
				break;
			}
		}
		//入れ替えても同じかどうか出力
		if(canSwap){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}
0