use std::io::Read; fn end_pattern(talk: String, matcher: &str) -> bool { let length = talk.len(); let temp = talk.rfind(matcher); temp.is_some() && temp.unwrap() + matcher.len() + 3 >= length && talk.chars() .filter(|c| c.is_ascii_alphanumeric()) .map(|c| c.to_string()) .collect::>() .join("") .ends_with(matcher) } fn main() { let mut all_data = String::new(); std::io::stdin().read_to_string(&mut all_data).ok(); let talks: Vec<_> = all_data.trim().split('\n').collect(); for t in talks.iter() { let mut flg = false; if t.len() <= 5 { flg = false; } else { let (talker, talk) = t.split_at(5); match talker { "digi " => { flg = end_pattern(talk.trim().to_ascii_lowercase(), "nyo"); }, "petit" => { flg = end_pattern(talk.trim().to_ascii_lowercase(), "nyu"); }, "rabi " => { flg = talk.trim().to_ascii_lowercase().chars().filter(|c| c.is_ascii_alphanumeric()).count() > 0; }, "gema " => { flg = end_pattern(talk.trim().to_ascii_lowercase(), "gema"); }, "piyo " => { flg = end_pattern(talk.trim().to_ascii_lowercase(), "pyo"); }, _ => {}, } } if flg { println!("CORRECT (maybe)"); } else { println!("WRONG!"); } } }