close
原文
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=976
感謝Lucky 貓大大中文翻譯
https://zerojudge.tw/ShowProblem?problemid=c014
C++
#include <iostream> using namespace std; int main() { int in1,in2,carry,ans; while(cin>>in1>>in2)//輸入測資 { if(in1==0&&in2==0)//兩個皆為零時中斷 { break; } ans=0;//歸零 carry=0; while((in1>=1)||(in2>=1))//只要兩數其中一個大於一 { //就要一直檢查進位 if(in1%10+in2%10+carry>=10)//取餘數就是取最小位的數 { carry=1;//有進位 ans=ans+1;//進位一次答案加一 } else { carry=0;//沒有進位 } in1=in1/10;//除十是把最小位去掉 in2=in2/10;//如此一位數一位數完成計算 } //輸出 if(ans==0)//沒有進位 { cout<<"No carry operation."<<endl; } else if(ans==1)//一次進位最後不加s { cout<<ans<<" carry operation."<<endl; } else//多次進位最後要加s { cout<<ans<<" carry operations."<<endl; } } return 0; }
文章標籤
全站熱搜