結果

問題 No.69 文字を自由に並び替え
ユーザー tsunabittsunabit
提出日時 2018-04-22 04:21:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 3,422 ms
コンパイル使用メモリ 74,036 KB
実行使用メモリ 56,508 KB
最終ジャッジ日時 2023-08-21 00:03:01
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,092 KB
testcase_01 AC 113 ms
55,804 KB
testcase_02 AC 115 ms
55,428 KB
testcase_03 AC 114 ms
56,092 KB
testcase_04 AC 115 ms
56,288 KB
testcase_05 AC 111 ms
54,276 KB
testcase_06 AC 112 ms
56,492 KB
testcase_07 AC 112 ms
55,684 KB
testcase_08 AC 112 ms
55,972 KB
testcase_09 AC 112 ms
55,648 KB
testcase_10 AC 112 ms
56,508 KB
testcase_11 AC 114 ms
56,028 KB
testcase_12 AC 114 ms
56,280 KB
testcase_13 AC 114 ms
55,900 KB
testcase_14 AC 114 ms
55,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

// ***問題文***
// 同じ長さの文字列Aと文字列Bが与えられる。
// 文字列Aの順番を自由に並び替えることができる。
// 文字列Aと文字列Bを同じにできるか判定せよ。
// ***入力***
// A
// B
// 文字列Aと文字列Bは1文字以上10文字以内の文字列。
// 文字列Aの長さと文字列Bの長さはかならず同じ。
// 文字はすべて小文字のアルファベットaからzで構成される。
// ***出力***
// 可能ならYES、不可能ならNOを出力せよ。
// 改行を忘れずに。

public class No69 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();

        String[] AA = A.split("",0);
        String[] BB = B.split("",0);

        ArrayList<String> aal = new ArrayList<String>(Arrays.asList(AA));
        Collections.sort(aal);
        ArrayList<String> bbl = new ArrayList<String>(Arrays.asList(BB));
        Collections.sort(bbl);

        boolean flag = true;
        for(int i = 0; i < aal.size(); i++) {
            if(!(aal.get(i).equals(bbl.get(i)))) {
                flag = false;
            }
        }

        if(flag == true) {
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}
0