結果
| 問題 |
No.2086 A+B問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-07 23:33:34 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 994 bytes |
| コンパイル時間 | 3,333 ms |
| コンパイル使用メモリ | 251,392 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-07 23:33:38 |
| 合計ジャッジ時間 | 4,103 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.hpp"
#else
#define debug(...) ((void)0)
#endif
int main() {
constexpr char endl = '\n';
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string a, b;
cin >> a >> b;
vector<int> A, B;
for (int i = (int)a.size(); i--;)
A.push_back(a[i] - '0');
for (int i = (int)b.size(); i--;)
B.push_back(b[i] - '0');
int N = max(A.size(), B.size());
while ((int)A.size() < N)
A.push_back(0);
while ((int)B.size() < N)
B.push_back(0);
int r = 0;
vector<int> ans;
int i = 0;
while (i < N || r > 0) {
int t = (i < N ? A[i] : 0), s = (i < N ? B[i] : 0);
if (t + s + r >= 10) {
ans.push_back((t + s + r) % 10);
r = (t + s + r) / 10;
} else {
ans.push_back(t + s + r);
r = 0;
}
i += 1;
}
string ret = "";
while ((int)ans.size() > 0) {
ret += to_string(ans.back());
ans.pop_back();
}
cout << ret << endl;
return 0;
}