#include <iostream>
using namespace std;
int max(int x, int y);
int main()
{
int a,b;
while(cin>>a>>b)
{
if(a==0 && b==0)
return 0;
int ar[10],br[10],cr[10]={0};
int ac=0,bc=0;
while(a>0){
ar[ac]=a%10;
a/=10;
ac++;
}
while(b>0){
br[bc]=b%10;
b/=10;
bc++;
}
int t=0;
for(int i=0; i<max(ac,bc); i++){//max 條件,避免位數不同,例如 999+1
cr[0]=0;
if(ar[i]+br[i]+cr[i]>=10){
t++;
cr[i+1]=1;
}
}
switch(t){
case 0 : cout<<"No carry operation.";break;
case 1 : cout<<"1 carry operation.";break;
default: cout<<t<<" carry operations.";break;
}
cout<<endl;
}
system("PAUSE");
return 0;
}
int max(int x, int y)
{
if(x>y)
return x;
else
return y;
}
錯誤訊息:
與正確輸出不相符(line:87)
您的答案為: 3 carry operations.
正確答案為: 2 carry operations.