count-carry-problem-6
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Regional Students's 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.


x=eval(input())
for j in range(x):
	a,b=input().split()
	a=[int(i) for i in a]
	b=[int(i) for i in b]
	while len(a)<len(b):
		a=[0]+a
	while len(b)<len(a):
		b=[0]+b
	co=0
	c=0
	for i in range(len(a)-1,-1,-1):
		if a[i]+b[i]+c>=10:
			c=1
			co+=1
		else:
			c=0
	if co==0:
		print("No carry operation")
	elif co==1:
		print("1 carry operation")
	else:
		print(str(co)+" carry operations")


for _ in range(int(input())):
	a,b=input().split()
	x=min(len(a),len(b))
	#print a,b;
	c=0
	for i in range(x):
		if(ord(a[i])-48+ord(b[i])-48>9):
			c+=1
	if c>1:
		print(str(c)+" carry operations")
	elif c==1:
		print("1 carry operation")
	else:
		print("No carry operation")


def cary(a,b):
	temp1=a
	temp2=b
	count=0
	while(temp1!=0 and temp2!=0):
		digit1=temp1%10
		digit2=temp2%10
		if(digit1+digit2>9):
			count+=1
		temp1/=10
		temp2/=10
	if (count == 0):
		return "No carry operation";
	elif (count == 1):
		return "1 carry operation";
	else:
		return str(count) + " carry operations";

output=[]
test_cases=int(input())
for i in range(0,test_cases):
	list=[int(i) for i in input().split()]
	output.append(cary(list[0],list[1]))
	
for i in output:
	print(i)


for ti in range(int(input())):
	f,s=list(map(str,input().split()))
	c=0
	for i in range(len(f)):
		sum=int(f[i])+int(s[i])
		if sum>=10:
			c=c+1
	if c==0:
		print("No carry operation")
	elif c==1:
		print(c,"carry operation")
	else:
		print(c,"carry operations")


t=eval(input())
while t>0:
	count=0
	a,b=list(map(int,input().split()))
	c=0
	while a!=0 and b!=0:
		x=a%10
		y=b%10
		z=x+y+c
		if z>9:
			c=z-9
			count+=1
		a=a/10
		b=b/10
	if count==0:
		print("No carry operation")
	else:
		if count==1:
			print(count,"carry operation")
		else:
			print(count,"carry operations") 
	t-=1


no_of_test_cases = int(input())
 
 
def countCarryOp(no1, no2):
	no1Digits = []
	no2Digits = []
	
	while(no1 != 0):
		no1Digits.append(no1 % 10)
		no1 = no1/10
	
	while(no2 != 0):
		no2Digits.append(no2 % 10)
		no2 = no2/10
		
	minLen = min(len(no1Digits), len(no2Digits))
	carryCount = 0
	carry = 0
	
	for i in range(0,minLen):
		if(no1Digits[i] + no2Digits[i] + carry > 9):
			carryCount += 1
			carry = 1
		else:
			carry = 0
	
	if(carryCount == 0):
		return "No carry operation"
	elif(carryCount == 1):
		return "1 carry operation"
	else:
		return str(carryCount) + " carry operations"
	
 
for i in range(1,no_of_test_cases + 1):
	no1, no2 = input().split(" ")
	no1, no2 = int(no1),int(no2)
	print(countCarryOp(no1, no2))
	


def cary(a,b):
	temp1=a
	temp2=b
	count=0
	while(temp1!=0 and temp2!=0):
		digit1=temp1%10
		digit2=temp2%10
		if(digit1+digit2>9):
			count+=1
		temp1/=10
		temp2/=10
	if (count == 0):
		return "No carry operation";
	elif (count == 1):
		return "1 carry operation";
	else:
		return str(count) + " carry operations";

output=[]
test_cases=int(input())
for i in range(0,test_cases):
	list=[int(i) for i in input().split()]
	output.append(cary(list[0],list[1]))
	
for i in output:
	print(i)


cases=int(input())
result=[]
i=1
while i<=cases:
	num1,num2=input().split()
	l1=len(num1)
	l2=len(num2)
	if l1 < l2 :
		min=num1
		max=num2
	else:
		min=num2
		max=num1
	min=min[::-1]
	max=max[::-1]
	count=0
	f=0
	for j in range (len(max)):
		digit1=int(max[j])
		digit2=int(min[j])
		if digit1+digit2+f > 9 :
		   count+=1
		   f=1
		else:
			f=0
	result.append(count)
	i+=1
for item in result:
	if item == 0:
		s="No carry operation"
	else:
		if item > 1:
			s=str(item)+" carry operations"
		else:
				s=str(item)+" carry operation"
	print(s)





t=eval(input())
for i in range(t):
	n1,n2=list(map(int,input().split(' ')))
	cnt=0
	#cry=0
	while(n1!=0 and n2!=0):
		tmp1=n1%10
		tmp2=n2%10
		if(tmp1+tmp2>=10):
			cnt+=1
		#	cry=(tmp1+tmp2)/10;
			#print cry
		n1=n1/10
		n2=n2/10
	if(cnt>1):
		print(cnt,"carry operations")
	elif(cnt==1):
		print(cnt,"carry operation")
	else:
		print("No carry operation")



t=int(input())
final=[]
for i in range(t):
	nums=input().split()
	counter=0
	n1=list(nums[0])
	n2=list(nums[1])
	if (len(n1)==0) or (len(n2)==0):
		final.append("No carry operations")
	elif len(n1) <= len(n2):
		for n in range(len(n1)):
			if (int(n1[len(n1)-1-n]))+(int(n2[len(n2)-1-n])) >= 10:
				counter=counter+1
	elif len(n2) <= len(n1):
		for o in range(len(n2)):
			if (int(n1[len(n1)-1-o]))+(int(n2[len(n2)-1-o])) >= 10:
				counter=counter+1
	if counter==0:
		final.append("No carry operation")
	elif counter==1:
		final.append(str(counter)+" carry operation")
	else:
		final.append(str(counter)+" carry operations")
for g in final:
	print(g)


global count
count=0
global carry
carry=0

def out(int1, int2):
	b=max(int1, int2)
	c=min(int1, int2)
	a=min(len(str(int1)), len(str(int2)))
	b=list(str(b))
	c=list(str(c))
	b=[int(b[i]) for i in range(len(b))]
	c=[int(c[i]) for i in range(len(c))]
	for i in range(1, a+1):
		if b[-i]+c[-i]+carry>9:
			global carry
			carry=b[-i]+c[-i]+carry-9
			global count
			count+=1
		else:
			carry=0
	if count==0:
		print("No carry operation")
	elif count>1:
		print("%d carry operations" %count)
	else:
		print("1 carry operation")
	count=0
	carry=0


t=eval(input())
for i in range(t):
	int1, int2=list(map(int, input().split()))
	out(int1, int2)