count-carry-problem-5

Subodhians 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:
for _ in range(int(input())):
	H,M=input().split()
	x=list(map(int,H))[::-1]
	y=list(map(int,M))[::-1]
	carry=0
	ans=0
	for i in range(len(x)):
		if x[i]+y[i] + carry>9:
			carry+=1
			ans+=1

		else:
			carry=0

	if ans==0:
		print("No carry operation")

	elif ans==1:
		print("1 carry operation")

	else:
		print(ans,"carry operations")


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


from string import zfill

for _ in range(eval(input())):
	a, b   = input().split() 
	la = len(a)
	lb = len(b)
	if la == lb:
		a1 = str(a)
		b1 = str(b)
	if la < lb :
		a1 = str(a).zfill(lb)
		b1 = str(b)        
	if lb < la:
		b1 = str(b).zfill(la)
		a1 = str(a)
	   
	a1 = a1[::-1]
	b1 = b1[::-1]
	carries = 0
	carryCnt= 0
	for x in range(len(a1)):
		curr = int(a1[x]) + int(b1[x]) + carries
		if curr >= 10:
			carryCnt +=1
			carries = 1
		else:
			carries = 0
		   
	if carryCnt <=  0:
		print('No carry operation')
	if carryCnt == 1:
		print('1 carry operation')
	if carryCnt > 1:
		print("%d carry operations" % carryCnt)