結果

問題 No.69 文字を自由に並び替え
コンテスト
ユーザー muston
提出日時 2016-06-01 09:06:28
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 850 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,241 ms
コンパイル使用メモリ 83,348 KB
実行使用メモリ 46,468 KB
最終ジャッジ日時 2026-05-25 00:09:56
合計ジャッジ時間 5,221 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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