結果

問題 No.49 算数の宿題
ユーザー tabataba
提出日時 2024-08-06 11:27:10
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 14,731 ms
コンパイル使用メモリ 393,500 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-06 11:27:25
合計ジャッジ時間 13,605 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused imports: `BTreeSet`, `HashMap`, `HashSet`
 --> src/main.rs:1:24
  |
1 | use std::collections::{BTreeSet, HashMap, HashSet};
  |                        ^^^^^^^^  ^^^^^^^  ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::collections::{BTreeSet, HashMap, HashSet};

use proconio::marker::Chars;

fn main() {
    proconio::input! {
        s: Chars,
    }
    let op_indexes = s
        .iter()
        .enumerate()
        .filter(|(_, c)| !c.is_numeric())
        .map(|(i, _)| i)
        .collect::<Vec<_>>();
    let mut values: Vec<i64> = vec![];
    let mut i = 0;
    for &op_index in op_indexes.iter() {
        values.push(s[i..op_index].iter().collect::<String>().parse().unwrap());
        i = op_index + 1;
    }
    values.push(s[i..].iter().collect::<String>().parse().unwrap());
    eprintln!("{:?}", values);
    let mut ans = values[0];
    for (i, op) in op_indexes
        .into_iter()
        .map(|op_index| s[op_index])
        .enumerate()
    {
        match op {
            '+' => ans *= values[i + 1],
            '*' => ans += values[i + 1],
            _ => unreachable!(),
        }
    }
    println!("{}", ans);
}
0