結果

問題 No.1168 Digit Sum Sequence
ユーザー Konton7
提出日時 2020-08-17 21:42:32
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 787 bytes
コンパイル時間 21,485 ms
コンパイル使用メモリ 373,788 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 11:18:32
合計ジャッジ時間 15,508 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 2
other RE * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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