/*
大数加法模板
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<stack>
using namespace std;
int T;
char s1[1001],s2[1001];
int ca,up;
stack<int> sta;
int main()
{
while(cin>>T)
{
ca=1;
while(T--)
{
scanf("%s%s",s1,s2);
int len1=strlen(s1)-1,len2=strlen(s2)-1;
up=0;
int temp;
for(;len1>=0 && len2>=0;len1--,len2--)
{
temp = (s1[len1] + s2[len2] - '0' - '0' + up);
if(temp >= 10)
{
up=1;
}
else up=0;
if(len1 || len2)
sta.push(temp%10);
else
sta.push(temp);
}
for(int i=len1;i>=0;i--)
{
temp = (s1[i] - '0' + up);
if(temp >= 10)
{
up=1;
}
else up=0;
if(i)
sta.push(temp%10);
else
sta.push(temp);
}
for(int i=len2;i>=0;i--)
{
temp = (s2[i] - '0' + up);
if(temp >= 10)
{
up=1;
}
else up=0;
if(i)
sta.push(temp%10);
else
sta.push(temp);
}
cout<<"Case "<<ca++<<":"<<endl;
cout<<s1<<" + "<<s2<<" = ";
while(!sta.empty())
{
printf("%d",sta.top());
sta.pop();
}
printf("\n");
if(T) printf("\n");
}
}
return 0;
}
大数加法模板
最新推荐文章于 2020-02-28 14:51:43 发布