結果

問題 No.1168 Digit Sum Sequence
コンテスト
ユーザー Konton7
提出日時 2020-08-17 21:42:32
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
RE  
実行時間 -
コード長 787 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 384 ms
コンパイル使用メモリ 176,964 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-13 22:45:56
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

fn digitsum(mut a: i32) -> i32 {
    let mut b = 0;
    loop{
        b += a % 10;
        a /= 10;
        if a == 0{
            break;
        }
    }
    return b;
}

fn main() {
    let inputstatus = 0;
    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 mut iter = buf.split_whitespace();

    let mut n: i32 = iter.next().unwrap().parse().unwrap();
    for _ in 0..10 {
        n = digitsum(n);
    }
    println!("{}", n);

}
0