# Primary Arithmetic(UVA10035) ## [程式繳交區](https://hackmd.io/@Renektonn/B1dqsqqvyx/edit) ## 題目 [點我](https://onlinejudge.org/external/100/10035.pdf) ## 解題系統 [UVA](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=976) [ZJ](https://zerojudge.tw/ShowProblem?problemid=c014) ## 演算法 ``` 1.輸入整數a,b,當兩者皆為0時,結束 2.宣告整數c=0,ans=0 3.當a大於0或b大於0 3.1 如果a的個位數與b的個位數與c相加大於等於10 c=1 ans++ 3.2 否則 c=0 3.3 a除以10 b除以10 3.4 回到3 4.輸出ans 5.回到1 ``` ## 程式碼 ```cpp= #include <iostream> using namespace std; int main() { int a , b; while(1){ cin >> a >> b; if(a == 0 && b == 0) break; int c = 0; int ans = 0; while(a > 0 || b > 0){ if( (a % 10) + (b % 10) + c >= 10){ ans++; c = 1; } else { c = 0; } a /= 10; b /= 10; } if(ans == 0){ cout << "No carry operation.\n"; } else if(ans == 1){ cout << "1 carry operation.\n"; } else{ cout << ans << " carry operations.\n"; } } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up