杭电acm1002,一直都是Wrong Answer,求解
测试多次,改正了一些错误,但始终都是不能AC,求高手!#include<iostream>#include<string>usingnamespacestd;intmai...
测试多次,改正了一些错误,但始终都是不能AC,求高手!
#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 sum_rs[1001]={0},data1[1001]={0},data2[1001]={0};
string a[20]={""},b[20]={""};
cin>>num_case;
for (int i = 0; i < num_case; i++)
{
cin>>a[i];
cin>>b[i];
}
for (int i = 0; i < num_case; i++)
{
//清空数据
memset(data1,0,sizeof(data1));
memset(data2,0,sizeof(data2));
index=0;
data1_str=a[i];
data2_str=b[i];
data1_size=data1_str.length();
data2_size=data2_str.length();
for(int j=0;j<data1_size;j++){
char tmp=data1_str[data1_size-j-1];
data1[j]=atoi(&tmp);
}
for(int j=0;j<data2_size;j++){
char tmp=data2_str[data2_size-j-1];
data2[j]=atoi(&tmp);
}
for (int 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 (int 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;
} 展开
#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 sum_rs[1001]={0},data1[1001]={0},data2[1001]={0};
string a[20]={""},b[20]={""};
cin>>num_case;
for (int i = 0; i < num_case; i++)
{
cin>>a[i];
cin>>b[i];
}
for (int i = 0; i < num_case; i++)
{
//清空数据
memset(data1,0,sizeof(data1));
memset(data2,0,sizeof(data2));
index=0;
data1_str=a[i];
data2_str=b[i];
data1_size=data1_str.length();
data2_size=data2_str.length();
for(int j=0;j<data1_size;j++){
char tmp=data1_str[data1_size-j-1];
data1[j]=atoi(&tmp);
}
for(int j=0;j<data2_size;j++){
char tmp=data2_str[data2_size-j-1];
data2[j]=atoi(&tmp);
}
for (int 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 (int 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;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询