Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Why PE ?

Posted by dennismv at 2005-10-06 12:27:40 on Problem 2562
 #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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator