プログラミングのお題スレ Part22 (863レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
469: デフォルトの名無しさん [sage] 01/03(金)20:07 ID:yesC/P5F(1)
>>464
fn is_ab_lang(input: &str) -> bool {
match input
.chars()
.fold(Some(0), |state, char| match (state, char) {
(Some(count), 'A') => Some(count + 1),
(Some(count), 'B') if count > 0 => Some(count - 1),
_ => None,
}) {
Some(0) => true,
_ => false,
}
}
fn main() {
for s in ["", "AB", "AABB", "ABAABBAAABBB"] {
assert!(is_ab_lang(s)); // true
}
for s in ["A", "B", "BA", "ABB", "AAB", "ABBA"] {
assert!(!is_ab_lang(s)); // false
}
}
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.043s