結果

問題 No.1005 BOT対策
ユーザー iwot
提出日時 2020-05-25 21:41:04
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 694 bytes
コンパイル時間 22,135 ms
コンパイル使用メモリ 403,528 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-13 02:15:04
合計ジャッジ時間 13,756 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 23 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn main() {
  let s: String = read();
  let t: String = read();
  println!("{}", no1005(s,t));
}

fn no1005(s: String, t: String) -> i32 {
  if t.len() == 1 && s.contains(t.chars().next().unwrap()) {
    -1
  } else if t.len() > s.len() {
    0
  } else {
    let mut result = None;
    for i in 0..s.len() - t.len() + 1 {
      let sub = format!("{}", &s.as_str()[i..i+t.len()]);
      if sub == t {
        result = match result {
          None => Some(1),
          Some(v) => Some(v+1),
        };
      }
    }
    result.unwrap_or(0)
  }
}
0