結果

問題 No.791 うし数列
ユーザー tsunekoh
提出日時 2019-05-02 10:13:10
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 527 bytes
コンパイル時間 14,427 ms
コンパイル使用メモリ 386,676 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-31 13:12:55
合計ジャッジ時間 13,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() -> Result<(), std::io::Error> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let input_str = s.trim().to_string();

    let top_is_one = input_str.chars().nth(0).unwrap() == '1';

    let mut ans = 0;
    for i in input_str.chars().skip(1) {
        if i == '3' {
            ans += 1;
        } else {
            ans = -1;
            break;
        }
    }

    if top_is_one && ans != 0 {
        println!("{}", ans);
    } else {
        println!("{}", -1);
    }

    Ok(())
}
0