---
# System prepended metadata

title: UVA 10035 Primary Arithmetic

---

# UVA 10035 Primary Arithmetic
##  題目連結 [UVA 10035](https://vjudge.net/problem/UVA-10035)
### 題目內容
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.
### 解題思路
利用div函示將數字拆成單一元素存入陣列中，再將每個位置做加法，如果大於或等於10時就將下一項加1，並ans++。
### 程式碼
```cpp=
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long x,y;
    while(cin>>x>>y){
        int step=0;
        if(x==0 && y==0)break;
        else{
            int temp=0;
            while(x!=0 || y!=0){
                if(x%10+y%10+temp>=10){
                    step++;
                    temp=1;
                }
                else{
                    temp=0;
                }
                x/=10;
                y/=10;
            }
        }
        if(step==0){
            cout<<"No carry operation."<<endl;
        }
        else if(step==1){
            cout<<"1 carry operation."<<endl;
        }
        else{
            printf("%d carry operations.\n",step);
        }
    }
}

```
## 測資
### Sample input
123 456
555 555
123 594
0 0
### Sample output
No carry operation.
3 carry operations.
1 carry operation.
##  中文題目連結 [zerojudge c014](https://zerojudge.tw/ShowProblem?problemid=c014)