count-carry-problem-2

Students are taught to add multi-digit numbers from right-to-left one digit at a time.
Many find the "carry" operation - in which 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 addition problem so that educators may assess their difficulty.

For the input first line contains n number of records which is less then 1000. And then each line contains two numbers with spacing between them as shown in sample. 

SAMPLE INPUT
3
123 456
555 555
123 594

SAMPLE OUTPUT
No carry operation
3 carry operations
1 carry operation

Explanation

EXAMPLE 1:-

when the digits are added then there is no carry found as 3+6=9,2+5=7 and 1+4=5.

EXAMPLE 2:-

when the digits are added then carry is generated as 5+5 =10 so carry is found 3 times.

EXAMPLE 3:-

when the digits 9 and 2 are added only then carry is found so 1 time only.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
t = int(input())
for i in range(t):
	i1 = list(map(int, input().split(' ')))
	carryCount = 0
	carry = 0
	
	while i1[0] != 0 and i1[1] != 0:
		#print i1[0] % 10 + i1[1] % 10 + carry
		if i1[0] % 10 + i1[1] % 10 + carry > 9:
			carryCount = carryCount + 1
			#print carryCount
			carry = 1
		else:
			carry = 0
		i1[0] = i1[0] / 10
		i1[1] = i1[1] / 10
	#print "dasd", carryCount
	if carryCount == 0:
		print("No carry operation")
	elif carryCount == 1:
		print("1 carry operation")	
	else:
		print("{} carry operations".format(carryCount))


for _ in range(eval(input())):
	a, b = input().split()
	a = list(map(int, list(a)))
	b = list(map(int, list(b)))
	i = len(a)-1
	j = len(b)-1
	flg = 0
	while(i>=0 and j>=0):
		if b[i]+a[j]>=10:
			flg+=1
		i-=1
		j-=1
	if flg==1:
		print(flg,"carry operation")
	elif flg>1:
		print(flg,"carry operations")
	else:
		print("No carry operation")


for _ in range(eval(input())):
	a,b=list(map(int, input().split()))
	while a!=0 and b!=0:
		cnt,f=0,0
		while True:
			c,d=a%10,b%10
			if c+d+f>=10:
				f=1
				cnt+=1
			else:
				f=0
			a/=10
			b/=10
			if a==0 and b==0:
				break
	if cnt==0:
		print("No carry operation ")
	elif cnt==1:
		print(str(cnt)+" carry operation")
	else:
		print(str(cnt)+" carry operations")
	


for _ in range(eval(input())):
	a,b=input().split()
	x=len(a)-1
	y=len(b)-1
	carry=0
	count=0
	while x>=0 and y>=0:
		z=int(a[x])+int(b[y])+carry
		carry=z/10
		if carry!=0:count+=1
		x-=1
		y-=1
	if x>y:
		while x>=0 and carry:
			z=a[x]+carry
			carry=z/10
			if carry:count+=1
			x-=1
	else:		
		while y>=0 and carry:
			z=b[y]+carry
			carry=z/10
			if carry:count+=1
			y-=1	
	if carry>9:count+=1		
	if count==0:print("No carry operation")
	elif count==1:print(1,"carry operation")
	else:print(count,"carry operations")	
		


t=eval(input())
for _ in range(t):
	l=list(map(int,input().split()))
	a=l[0]
	b=0
	if len(l)>1:
		b=l[1]
	carry=0
	cnt=0
	if not a or not b:
		print("No carry operation")
		continue
	while a or b:
		s=a%10+b%10+carry
		if s>=10: 
			carry=1
			cnt+=1
		else:
			carry=0
		a/=10
		b/=10
	if not cnt:
		print("No", end=' ')
	else:
		print(cnt, end=' ')
	if cnt<2:
		print("carry operation")
	else:
		print("carry operations")


for _ in range(eval(input())):
	a,b=input().split()
	x=len(a)-1
	y=len(b)-1
	carry=0
	count=0
	while x>=0 and y>=0:
		z=int(a[x])+int(b[y])+carry
		carry=z/10
		if carry!=0:count+=1
		x-=1
		y-=1
	if x>y:
		while x>=0 and carry:
			z=a[x]+carry
			carry=z/10
			if carry:count+=1
			x-=1
	else:		
		while y>=0 and carry:
			z=b[y]+carry
			carry=z/10
			if carry:count+=1
			y-=1	
	if carry>9:count+=1		
	if count==0:print("No carry operation")
	elif count==1:print(1,"carry operation")
	else:print(count,"carry operations")	
		


t = int(input())
while t != 0 :
	c = 0
	n = input().split()
	a = n[0][::-1]
	b = n[1][::-1]
	for i,j in map(None,a,b):
		if i == None: i = 0
		if j == None: j = 0
		if (int(i) + int(j) + c) > 9: c = c + 1
	
	if c == 0 : print("No carry operation")
	elif c == 1: print("1 carry operation")
	else:
		print("%s carry operations" % c)
		
	t = t - 1