I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
2 1 2 112233445566778899 998877665544332211
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int cnt = 1;
int main()
{
int n;
cin >> n;
string a,b;
string c,d;
while(n--)
{
cin >> a >> b;
c = a,d = b;
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
int lena = a.length();
int lenb = b.length();
if(lena > lenb)
{
b.append(lena-lenb,'0');
lenb = lena;
}
else
{
a.append(lenb-lena,'0');
lena = lenb;
}
vector<char>v;
int array = 0;
int num;
for(int i = 0;i < lena;i++)
{
num = a[i]-'0'+b[i]-'0';
v.push_back((num+array)%10+'0');
array = (num+array)/10;
}
if(array)
v.push_back(array+'0');
printf("Case %d:\n",cnt++);
cout << c << " + " << d << " = ";
for(int i = v.size()-1;i >= 0;i--)
cout << v[i];
cout << endl;
if(n != 0)
cout << endl;
}
return 0;
}