結果

問題 No.581 XOR
ユーザー komkomhkomkomh
提出日時 2019-06-10 15:29:11
言語 Kotlin
(1.9.10)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 12,557 ms
コンパイル使用メモリ 420,096 KB
実行使用メモリ 54,776 KB
最終ジャッジ日時 2023-08-13 02:34:04
合計ジャッジ時間 16,329 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 291 ms
52,900 KB
testcase_01 AC 296 ms
52,956 KB
testcase_02 AC 296 ms
52,944 KB
testcase_03 AC 301 ms
54,776 KB
testcase_04 AC 298 ms
53,072 KB
testcase_05 AC 295 ms
53,028 KB
testcase_06 AC 295 ms
53,012 KB
testcase_07 AC 295 ms
52,956 KB
testcase_08 AC 301 ms
52,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder

fun main() {
    val (A, C) = readLine()!!.split(" ").map(String::toLong)
    val A2: String = A.toString(2)
    val C2: String = C.toString(2)

    val maxLength = when (A2.length > C2.length) {
        true -> A2.length
        false -> C2.length
    }

    val padA2 = A2.padStart(maxLength, '0')
    val padC2 = C2.padStart(maxLength, '0')

    val chars: CharArray = (0 until maxLength).map {
        val a = padA2[it]
        val c = padC2[it]
        when (a == c) {
            true -> '0'
            false -> '1'
        }
    }.toCharArray()

    val ans:Long = String(chars).toLong(2)
    println(ans)
}
0