結果

問題 No.69 文字を自由に並び替え
ユーザー wf4n9wf4n9
提出日時 2017-10-13 10:32:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 988 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 72,140 KB
実行使用メモリ 40,000 KB
最終ジャッジ日時 2023-08-20 23:49:53
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
39,388 KB
testcase_01 AC 112 ms
39,128 KB
testcase_02 AC 113 ms
39,160 KB
testcase_03 AC 119 ms
39,832 KB
testcase_04 AC 114 ms
39,544 KB
testcase_05 AC 115 ms
39,124 KB
testcase_06 AC 114 ms
39,124 KB
testcase_07 AC 120 ms
39,796 KB
testcase_08 AC 117 ms
39,540 KB
testcase_09 AC 118 ms
39,380 KB
testcase_10 AC 114 ms
39,140 KB
testcase_11 AC 114 ms
39,520 KB
testcase_12 AC 121 ms
40,000 KB
testcase_13 AC 116 ms
39,308 KB
testcase_14 AC 113 ms
39,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static final String YES = "YES";
	public static final String NO = "NO";
	public static final char CHECKED = '-';

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String inputA = sc.nextLine();
		String inputB = sc.nextLine();

		System.out.println(canRearrange(inputA, inputB));
	}

	public static String canRearrange(final String inputA, final String inputB) {

		// 配列の長さの一致を確認
		if (inputA.length() != inputB.length()) {
			return NO;
		}

		// char配列に変換
		char[] charArrayA = inputA.toCharArray();
		char[] charArrayB = inputB.toCharArray();

		// 順番に存在するか確認
		for (int i = 0; i < charArrayA.length; i++) {
			boolean found = false;
			for(int j = 0; j < charArrayB.length; j++) {
				if (charArrayA[i] == charArrayB[j]) {
					found = true;
					charArrayB[j] = CHECKED;
					break;
				}
			}
			if(!found) return NO;
		}
		return YES;
	}
}
0