結果

問題 No.2086 A+B問題
ユーザー a01sa01toa01sa01to
提出日時 2023-07-05 00:37:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 200,872 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-25 23:31:06
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,500 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
  #define _GLIBCXX_DEBUG
#else
  #define Debug(...) void(0)
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  string a, b;
  cin >> a >> b;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  string ans = "";
  rep(i, max(a.size(), b.size())) {
    int x = (i >= a.size() ? 0 : a[i] - '0');
    int y = (i >= b.size() ? 0 : b[i] - '0');
    if (x + y >= 10) {
      ans += to_string((x + y) % 10);
      if (i >= a.size() - 1 && i >= b.size() - 1) {
        ans += "1";
      }
      else if (i >= a.size() - 1) {
        a[i + 1]++;
      }
      else {
        b[i + 1]++;
      }
    }
    else {
      ans += to_string(x + y);
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}
0