Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why PE ?#include <iostream> using namespace std; int primaryarithmetic(unsigned int a,unsigned int b) //returns the # of carry operations { int carry=0; int totalcarry=0; unsigned int adigit,bdigit; //to record extracted digits while (a>0 || b>0) { adigit=a%10; //extract ones a=(a-adigit)/10; bdigit=b%10; b=(b-bdigit)/10; if (adigit+bdigit+carry>9) { carry=1; totalcarry++; } else carry=0; } return totalcarry; } int main () { unsigned int a,b; int carry; while (cin>>a>>b && (a!=0 || b!=0)) { carry=primaryarithmetic(a,b); switch (carry) { case 0: cout<<"No carry operation."<<endl;break; case 1: cout<<"1 carry operation."<<endl;break; default: cout<<carry<<" carry operations."<<endl; } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator