修改了几次,现在是在是没看出问题在哪,求指教,感激不尽。
#include<iostream>
#include<string>
using namespace std;
int main(){
int num_case=0;
string data1_str="",data2_str="";
int data1_size=0,data2_size=0;
int mark=0;
int index=0;
int j=0;
int sum_rs[1001]={0},data1[1001]={0},data2[1001]={0};
cin>>num_case;
for (int i = 0; i < num_case; i++)
{
memset(data1,0,sizeof(data1));
memset(data2,0,sizeof(data2));
index=0;
mark=0;
cin>>data1_str;
cin>>data2_str;
data1_size=data1_str.length();
data2_size=data2_str.length();
for(j=0;j<data1_size;j++){
char tmp=data1_str[data1_size-j-1];
data1[j]=atoi(&tmp);
}
for(j=0;j<data2_size;j++){
char tmp=data2_str[data2_size-j-1];
data2[j]=atoi(&tmp);
}
for (j = 0; j < 1001; j++)
{
sum_rs[j]=data1[j]+data2[j]+mark;
if (sum_rs[j]>=10)
{
sum_rs[j]%=10;
mark=1;
}else
{
mark=0;
}
}
for (j =0; j < 1001; j++)
{
if (sum_rs[j]!=0)
{
index=j;
}
}
cout<<"Case "<<i+1<<":"<<endl;
cout<<data1_str<<" + "<<data2_str<<" = ";
for (int j =index; j >=0; j--)
{
cout<<sum_rs[j];
}
cout<<endl;
if(i!=num_case-1) cout<<endl;
}
return 0;
}