結果

問題 No.2086 A+B問題
ユーザー hayatroid
提出日時 2022-10-01 20:15:00
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 13,406 ms
コンパイル使用メモリ 378,852 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 03:20:21
合計ジャッジ時間 13,353 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read() -> Vec<u8> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().bytes().map(|x| x - b'0').collect::<Vec<_>>()
}

fn main() {
    let a = read().into_iter().rev().collect::<Vec<_>>();
    let b = read().into_iter().rev().collect::<Vec<_>>();
    let mut carry = 0;
    let mut ans = String::new();
    for i in 0..a.len().max(b.len()) {
        let mut tmp = carry;
        carry = 0;
        if i < a.len() {
            tmp += a[i];
        }
        if i < b.len() {
            tmp += b[i];
        }
        if tmp >= 10 {
            tmp -= 10;
            carry = 1;
        }
        ans = format!("{}{}", tmp, ans);
    }
    if carry > 0 {
        ans = format!("{}{}", carry, ans);
    }
    println!("{}", ans);
}
0