結果

問題 No.2086 A+B問題
ユーザー lam6er
提出日時 2025-03-20 18:58:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 53,820 KB
最終ジャッジ日時 2025-03-20 18:59:20
合計ジャッジ時間 1,675 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

a = input().strip()
b = input().strip()

a_rev = a[::-1]
b_rev = b[::-1]

max_len = max(len(a_rev), len(b_rev))

carry = 0
result = []

for i in range(max_len):
    digit_a = int(a_rev[i]) if i < len(a_rev) else 0
    digit_b = int(b_rev[i]) if i < len(b_rev) else 0
    total = digit_a + digit_b + carry
    carry = total // 10
    result.append(total % 10)

if carry > 0:
    result.append(carry)

# Reverse to get the correct order and remove any trailing zeros (though sum won't have leading zeros except when 0)
result.reverse()

# Handle the case where the result is zero (to avoid empty string)
sum_str = ''.join(map(str, result))
print(sum_str)
0