結果

問題 No.380 悪の台本
ユーザー phsplsphspls
提出日時 2020-06-20 18:10:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 1,520 bytes
コンパイル時間 971 ms
コンパイル使用メモリ 145,744 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 17:41:32
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 124 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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::<Vec<String>>()
        .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.split_terminator('\n').collect();

    for t in talks.iter() {
        let mut flg = false;
        if t.len() <= 5 { 
            flg = false;
        } else {
            let split_val = if t.starts_with("petit") { 6 } else { 5 };
            let (talker, talk) = t.split_at(split_val);
            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!");
        }
    }
}
0