#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
long long int a,b,k;
while(cin>>a>>b,a)
{ k=0;int x[11]={0},y[11]={0},z[12]={0};
for(int i=0;i<11,a;i++){x[i]=a%10;a/=10;}
for(int i=0;i<11,b;i++){y[i]=b%10;b/=10;}
for(int i=0;i<11;i++){z[i]=x[i]+y[i];}
for(int i=0;i<11;i++)
{
if(z[i]>=10){z[i+1]++,k++;}}
if(k==0){cout<<"No carry operation."<<endl;}
else if(k==1){cout<<"1 carry operation."<<endl;}
else{ cout<<k<<" carry operations."<<endl;}
}
return 0;
}
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
long long int a,b,k;
while(cin>>a>>b,a)
{ k=0;int x[11]={0},y[11]={0},z[12]={0};
for(int i=0;i<11,a;i++){x[i]=a%10;a/=10;}
for(int i=0;i<11,b;i++){y[i]=b%10;b/=10;}
for(int i=0;i<11;i++){z[i]=x[i]+y[i];}
for(int i=0;i<11;i++)
{
if(z[i]>=10){z[i+1]++,k++;}}
if(k==0){cout<<"No carry operation."<<endl;}
else if(k==1){cout<<"1 carry operation."<<endl;}
else{ cout<<k<<" carry operations."<<endl;}
}
return 0;
}
題目是說當 a b 皆為0時才算結束,
而你的寫法是當a = 0 時結束
稍微改一下就AC囉~~
若有幫到忙,還請幫我留個言,謝謝~~~
http://ntnuee40475032h.pixnet.net/blog