結果

問題 No.2021 Not A but B
ユーザー rururun
提出日時 2024-11-10 12:14:16
言語 Swift
(6.0.3)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 284 bytes
コンパイル時間 14,509 ms
コンパイル使用メモリ 126,004 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-11-10 12:14:32
合計ジャッジ時間 16,678 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

let n = Int(readLine()!)!
var s = readLine()!.map{String($0)}
s.append("A")
var cnt = 0, f = true
for i in 0...(n-2){
	if s[i] == "A"{
		cnt += 1
	}else{
	  if f && s[i+1] == "B"{
	    cnt += 1
	    f = false
	  }else if s[i+1] == "A" && s[i+2] == "A"{
			cnt += 1
		}
	}
}
print(cnt)
0