Carry Count
InterviewTime limit1sMemory limit128 MB
For each pair of non-negative integers, count how many carries occur while adding them column by column from the right. Stop at the 0 0 line.
- Level
Easy3 of 10
- Topics
- Implementation, Math, Simulation
- Solved
- No attempts yet
Problem
When adding multi-digit numbers, you add one column at a time starting from the rightmost digit and moving left. Whenever the sum of a single column is a two-digit number, you carry the 1 into the column immediately to its left. This is called a carry.
Given two integers, write a program that counts how many carries occur while adding them together.
Input
The input consists of several test cases. Each test case is a single line containing two integers, where each integer is a non-negative integer with at most 10 digits. The last line of the input is 0 0, and this line must not be processed.
Output
For each test case, print on its own line the number of carries that occur when the two numbers are added.