結果

問題 No.1159 Sashiming String
ユーザー Konton7
提出日時 2020-08-14 00:21:52
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1,992 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 12,643 ms
コンパイル使用メモリ 402,772 KB
実行使用メモリ 8,412 KB
最終ジャッジ日時 2024-10-09 19:37:57
合計ジャッジ時間 23,554 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::fs::File;
use std::io::Read;

fn main() {
    let inputstatus = 1;
    let mut buf = String::new();

    let filename = "inputrust.txt";

    if inputstatus == 0 {
        let mut f = File::open(filename).expect("file not found");
        f.read_to_string(&mut buf)
            .expect("something went wrong reading the file");
    } else {
        std::io::stdin().read_to_string(&mut buf).unwrap();
    }

    let s: &str = &buf;

    let mut s_list: Vec<i64> = Vec::new();
    let mut i_list: Vec<i64> = Vec::new();
    let mut n_list: Vec<i64> = Vec::new();
    let mut g_list: Vec<i64> = Vec::new();

    for i in 0..s.len() {
        let c = s.chars().nth(i).unwrap();
        if i == 0 {
            s_list.push(0);
            i_list.push(0);
            n_list.push(0);
            g_list.push(0);
        } else {
            s_list.push(s_list[i - 1]);
            i_list.push(0);
            n_list.push(0);
            g_list.push(g_list[i - 1]);
        }
        if c == 'S' {
            s_list[i] += 1;
        } else if c == 'i' {
            i_list[i] += s_list[i];
        } else if c == 'n' {
            n_list[i] += i_list[i-1];
        } else if c == 'g' {
            g_list[i] += n_list[i-1];
        }
    }

    // for v in s_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in i_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in n_list {
    //     print!("{} ", v);
    // }
    // println!("\n");
    // for v in g_list {
    //     print!("{} ", v);
    // }
    // println!("\n");

    println!("{}", g_list[s.len() - 1]);
}
0