#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <vector>
#define INF 0x3f3f3f3f
#define MS(x,y) memset(x, y, sizeof(x))
#define MOD 1000000007
#define LL long long int
using namespace std;
const int Len = 8;
const int Base = 100000000;
char s1[50010], s2[50010];
int d[10];
struct bigint
{
int v[150];
int lenth;
bigint()
{
lenth = 0;
for(int i=0;i<150;++i)
v[i] = 0;
}
void read(char* s)
{
lenth = 0;
for(int i=0;i<150;++i)
v[i] = 0;
int len = strlen(s);
int now = 0;
int num = 0;
for(int i=len-1;i>=0;--i)
{
num += (s[i]-'0')*d[now];
++now;
if(now == Len)
{
v[lenth++] = num;
now = num = 0;
}
}
if(now)
{
v[lenth++] = num;
}
}
void add(bigint x)
{
lenth = max(lenth, x.lenth);
int t = 0;
for(int i=0;i<lenth;++i)
{
v[i] += x.v[i]+t;
t = v[i]/Base;
v[i] %= Base;
}
if(t)
v[lenth++] = t;
}
void print()
{
bool lead = true;
for(int i = lenth-1;i >= 0;--i)
{
if(lead)
{
if(v[i] != 0)
{
printf("%d", v[i]);
lead = false;
}
}
else
{
printf("%08d", v[i]);
}
}
if(lead)
printf("0");
printf("\n");
}
};
bigint a,b;
int T;
int main()
{
//std::ios::sync_with_stdio(false);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
d[0] = 1;
for(int i=1;i<Len;++i)
d[i] = d[i-1]*10;
scanf("%d", &T);
for(int Case=1; Case<=T; ++Case)
{
scanf("%s%s", s1, s2);
printf("Case %d:\n", Case);
printf("%s + %s = ", s1, s2);
a.read(s1);
b.read(s2);
// a.print();
// b.print();
a.add(b);
a.print();
}
return 0;
}
bigint
最新推荐文章于 2024-10-11 00:15:00 发布