主题:浙江大学ACM 1874
这是我的程序,但是没通过,不知哪错了,
各位帮我找找
#include<iostream>
using namespace std;
int main()
{
long a,b;
long n[10],m[10],i,j,carry,sum,r;
while(cin>>a>>b)
{
sum=0;
if(a==0&&b==0)
break;
i=0;
while(a!=0)
{
m[i]=a%10;
a=a/10;
i++;
}
a=i-1;
j=0;
while(b!=0)
{
n[j]=b%10;
b=b/10;
j++;
}
b=j-1;
carry=0;
for(i=a,j=b;i>-1||j>-1;i--,j--)
{
if(i>=0&&j>=0)
{
r=m[i]+n[j]+carry;
if(carry=r/10)
sum++;
}
else if(i>=0&&j<0)
{
r=m[i]+carry;
if(carry=r/10)
sum++;
}
else
{
r=n[j]+carry;
if(carry=r/10)
sum++;
}
}
if(sum==0)
cout<<"No carry operation."<<endl;
else if(sum==1)
cout<<sum<<" carry operation."<<endl;
else
cout<<sum<<" carry operations."<<endl;
}
return 1;
}
各位帮我找找
#include<iostream>
using namespace std;
int main()
{
long a,b;
long n[10],m[10],i,j,carry,sum,r;
while(cin>>a>>b)
{
sum=0;
if(a==0&&b==0)
break;
i=0;
while(a!=0)
{
m[i]=a%10;
a=a/10;
i++;
}
a=i-1;
j=0;
while(b!=0)
{
n[j]=b%10;
b=b/10;
j++;
}
b=j-1;
carry=0;
for(i=a,j=b;i>-1||j>-1;i--,j--)
{
if(i>=0&&j>=0)
{
r=m[i]+n[j]+carry;
if(carry=r/10)
sum++;
}
else if(i>=0&&j<0)
{
r=m[i]+carry;
if(carry=r/10)
sum++;
}
else
{
r=n[j]+carry;
if(carry=r/10)
sum++;
}
}
if(sum==0)
cout<<"No carry operation."<<endl;
else if(sum==1)
cout<<sum<<" carry operation."<<endl;
else
cout<<sum<<" carry operations."<<endl;
}
return 1;
}