結果

問題 No.2086 A+B問題
ユーザー Master wwcMaster wwc
提出日時 2022-10-07 11:10:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 199,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 12:19:04
合計ジャッジ時間 3,314 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

void solve()
{
    string a,b,c; cin>>a>>b;
    
    int i=a.size()-1,j=b.size()-1,rem=0;
    while(i>=0 && j>=0)
    {
        int num = ((int)a[i]-48) + ((int)b[j]-48);
        num += rem;
        i--;
        j--;
        rem = num%10;
        c.push_back((char)rem+48);
        rem = num/10;
    }

    while(i>=0)
    {
        int num = (int)a[i]-48;
        num += rem;
        i--;
        rem = num%10;
        c.push_back((char)rem+48);
        rem = num/10;
    }

     while(j>=0)
    {
        int num = (int)b[j]-48;
        num += rem;
        j--;
        rem = num%10;
        c.push_back((char)rem+48);
        rem = num/10;
    }

    reverse(c.begin(),c.end());
    cout << c << "\n";
}

signed main(){

  ios_base::sync_with_stdio(false),cin.tie(0);
  cout.tie(0);

  solve();
}
0