注意这个输出格式,最后一个case后面不应该有空格
Poblem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases
Sample Input
2
1 2
112233445566778899 998877665544332211Sample Output
Case 1:
1 + 2 = 3Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
#include<iostream>
#include<string>
#include<cstring>//memset函数头文件
//#include<cstdio>//输出格式用printf方便
using namespace std;
//用数组来存放大正整数
struct bign{
int d[2000];
int len;
bign(){//结构体初始化
memset(d,0,sizeof(d));
len=0;
}
};
//将字符串转换为bign
bign change(string x){
bign a;
a.len=x.length();
for(int i=0;i<x.length();i++)
a.d[i]=x[x.length()-i-1]-'0';
return a;
}
//相加
bign add(bign a,bign b){
bign c;
int carry=0,temp;
for(int i=0;i<a.len||i<b.len;i++){
temp=a.d[i]+b.d[i]+carry;
c.d[i]=temp%10;
carry=temp/10;
c.len++;
}
if(carry!=0){
c.d[c.len++]=carry;
}
return c;
}
int main()
{
int n;
cin>>n;
string a,b;
for(int i=1;i<=n;i++){
cin>>a>>b;
bign ans=add(change(a),change(b));
//printf("Case %d:\n",i);
cout<<"Case "<<i<<":"<<endl;
//printf("%s + %s = ",a,b); //csdio没有字符串类型,%s只能用于字符串数组
cout<<a<<" + "<<b<<" = ";
for(int i=ans.len-1;i>=0;i--)
cout<<ans.d[i];
cout<<endl;//cout<<endl<<endl; 最后一个case后面不能有空格
if(i!=n) cout<<endl;
}
return 0;
}