結果

問題 No.559 swapAB列
ユーザー R_FR_F
提出日時 2017-11-28 17:44:54
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 13,606 ms
コンパイル使用メモリ 424,772 KB
実行使用メモリ 54,516 KB
最終ジャッジ日時 2023-08-12 21:28:14
合計ジャッジ時間 17,960 ms
ジャッジサーバーID
(参考情報)
judge2 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
54,308 KB
testcase_01 AC 329 ms
54,244 KB
testcase_02 AC 330 ms
54,100 KB
testcase_03 AC 327 ms
54,516 KB
testcase_04 AC 328 ms
54,096 KB
testcase_05 AC 328 ms
54,456 KB
testcase_06 AC 335 ms
54,184 KB
testcase_07 AC 328 ms
54,416 KB
testcase_08 AC 329 ms
54,172 KB
testcase_09 AC 328 ms
54,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:24:10: warning: parameter 'args' is never used
fun main(args: Array<String>){
         ^

ソースコード

diff #

import java.util.Scanner

fun inputListSplit(): MutableList<String>{
	var input = (Scanner(System. `in`).next()).split(Regex(""))
	var list: MutableList<String> = mutableListOf()
	for(i in 0..input.count() - 2) list.add(input[i])
	return list
}

fun swap(list: MutableList<String>): Int{
	var count: Int = 0
	var i: Int = 0
	while(i < list.count() - 1){
		if(list[i] == "B" && list[i + 1] == "A"){
			list[i] = list[i + 1].also {list[i + 1] = list[i]}
			count++
			if(i != 0 && list[i - 1] == "B") i -= 2
		}
		i++
	}
	return count
}

fun main(args: Array<String>){
	var list: MutableList<String> = inputListSplit()
	println( swap(list) )
}
0