不明白BUG在哪 求大神指导!
#include <iostream>using namespace std;
int main()
{
string a,b;
while(cin >> a >> b)
{
if(a == "0"&&b == "0")
return 0;
int a1 = a.length();
int b1 = b.length();
int num;
int h;
if(a1 > b1)
{
num = b1;
h=1;
}
if(a1 < b1)
{
num = a1;
h=2;
}
if(a1 == b1)
{
num = a1;
h = 0;
}
int temp = 0, count = 0;
for(int i = 0; i < num; i++)
{
if(a[a1-i-1]+b[b1-i-1]+temp-96>9)
{
count++;
temp = 1;
continue;
}
temp = 0;
}
if(temp == 1 )
{
if(h==1)
{
for(int i = 1; i < a1-num+1 ; i++)
{
if(a[a1-num-i]=='9')
{
count++;
}
if(a[a1-num-i]!='9')
{
break;
}
}
}
if(h==2)
{
for(int i = 1; i < b1 -num+1 ; i++)
{
if(b[b1-num-i]=='9')
{
count++;
}
if(b[b1-num-i]!='9')
{
break;
}
}
}
if(h == 0);
}
if(count != 0)
cout << count << " carry operations." << endl;
if(count == 0)
cout << "No carry operation." << endl;
}
return 0;
}
Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.
Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0. For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below.
Sample Input
123 456
555 555
123 594
0 0
Output for Sample Input
No carry operation.
3 carry operations.
1 carry operation.
题目如上...不知道错在那里...怎么样也不能提交...
POJ2562 TOJ1350 求大神指导!!!