Carry Count
1.0s 256MA student is practicing column addition. Whenever two digits plus the incoming carry add up to \(10\) or more, a carry is sent to the next digit on the left.
You are given several pairs of non-negative integers \(a\) and \(b\). For each pair, output how many carry operations occur when computing \(a + b\). The input ends with 0 0; this last pair should not produce output.
Syntax Restrictions
This problem uses the syntax restrictions of Unit 4 (Loops) of the syntax textbook. You may use if, else, loops, comparisons, logical operators, integer variables, cin, cout, and cout << endl; however, you may not use arrays or containers, and you may not use any function other than main (including built-in functions and user-defined functions). The name endl is allowed only as an output newline manipulator, not as a function call.
Your source code is checked automatically during judging. A submission that breaks the restrictions is judged SR (Syntax Restriction), and the judge feedback lists where the violation is.
Click to expand: allowed and forbidden syntax
Allowed:
#include <iostream>or other ordinary includes (no extra header is needed)using namespace std;- the
int main()function andreturn 0; - integer, Boolean, and character variables, such as
int,long long,bool, andchar - reading with
cin >>and printing withcout <<, includingcout << endl if,else,for, andwhile- arithmetic, comparison, and logical operators, such as
+,-,*,/,%,<,<=,==, and&& - assignment and increment/decrement, such as
=,+=,++, and-- - comments (
//and/* */)
Forbidden (common examples):
- arrays and indexing syntax
[] - containers or similar tools such as
vector,array,string,deque,map, andset - dynamic allocation syntax such as
newanddelete - any function call or function declaration other than
main, includingmax,min,abs,sqrt,pow,sort,swap,getline,printf, andscanf - non-include preprocessor directives such as
#define
Input
The input contains several lines. Each line contains two non-negative integers \(a\) and \(b\).
The last line is always 0 0, meaning the input ends. This last line should not produce output.
Constraints
- There is at least \(1\) and at most \(100\) data pairs before the final
0 0. - Each data pair satisfies \(0 \le a, b \le 1000000000\).
- Except for the final line, there is no pair with both \(a = 0\) and \(b = 0\).
- The memory limit is \(256\) MB.
Output
For each data pair, output one line with one integer: the number of carry operations when computing \(a + b\).
Sample Input 1
95 17
123 456
999 1
0 0
Sample Output 1
2
0
3
Sample Input 2
0 7
101 909
0 0
Sample Output 2
0
2
Log in to write and submit code. Creating an account is free.