count-carry-problem-4

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.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
t = eval(input())
while t > 0:
	a, b = list(map(str, input().split()))
	temp = min(int(a), int(b))
	lenght = len(str(temp))
	carry = 0
	for i in range(lenght):
		if (int(a[i]) + int(b[i])) >= 10:
			carry += 1
	if carry == 0:
		print("No carry operation")
	elif carry == 1:
		print("1 carry operation")
	else:
		print(str(carry) + " carry operations")
	t -= 1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n=int(input())
while n>0:
	n-=1
	carry=0
	nums=[list(x) for x in input().split(' ')]
	h=[]
	j=max( len(nums[0]),len(nums[1]) )
	for i in range(0,j ):
		h.append((nums[0][i],nums[1][i]))
	
	for (x,y) in h:
		a=ord(x)-ord('0')
		b=ord(y)-ord('0')
		if(a+b>9):
			carry+=1
	
	if carry==0:
		print("No carry operation")
	elif carry==1:
		print("1 carry operation")
	else:
		print(carry,"carry operations")


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


def func(x,y):
	count=0
	c=0
	if x>y:
		large=x
		small=y
	else:
		large=y
		small=x
	while large>0:
		d1=large%10
		d2=small%10
		s=d1+d2+c
		if s>9:
			c=s/10
			count+=1
		else:
			c=0
		large/=10
		small/=10
	return count

li=[]
t=int(eval(input()))
for i in range(t):
	a,b=input().split()
	a=int(a)
	b=int(b)
	r=func(a,b)
	li.append(r)
for i in range(t):
	if li[i]==0:
		print("No carry operation")
	elif li[i]==1:
		print("1 carry operation")
	else:
		print(str(li[i]) + " carry operations")


t=int(input())
for i in range(t):
	c=0
	a,b=input().strip().split(' ')
	a,b=[int(a),int(b)]
	while a>0 and b>0:
		if(a%10+b%10>=10):
			c+=1
		a,b=[int(a/10),int(b/10)]
	if c==0:
		print ("No carry operation")
	elif c==1:
		print ("1 carry operation")
	else:
		print((str(c)+" carry operations"))


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")


for _ in range(int(input())):
	a,b=list(map(int,input().split()))
	c=0
	cnt=0
	ad=[]
	bd=[]
	while(a!=0):
		ad.append(a%10)
		a=a/10
	while(b!=0):
		bd.append(b%10)
		b=b/10
	#print(ad,bd)
	if(len(ad)>=len(bd)):
		for i in range(len(bd)):
			if(c+bd[i]+ad[i]>=10):
				c=1
				cnt+=1
	else:
		for i in range(len(ad)):
			if(c+bd[i]+ad[i]>=10):
				c=1
				cnt+=1
	if(cnt==0):
		print ('No carry operation')
	elif(cnt==1):
		print('1 carry operation')
	else:
		print((str(cnt)+' carry operations'))


n  = int(input())
for i in range(n):
	s = input().split(' ')
	cr = 0
	c = 0
	for j in range(len(s[0])):
		p = int(s[0][len(s[0])-j-1]) + int(s[1][len(s[1])-j-1]) + cr
		if(p >= 10):
			c=c + 1
			cr = 1
		else:
			cr = 0
	if(c == 1):
		print(c,"carry operation")
	elif(c>1):
		print(c,"carry operations")
	else:
		print("No carry operation")


T = int(eval(input()))
for i in range(T):
	arr = list(map(int, input().split()))
	temp1 = arr[0]
	temp2 = arr[1]
	carry = 0
	c = 0
	while(temp1 > 0 or temp2 > 0):
		r1 = temp1 % 10
		r2 = temp2 % 10
		c = (r1 + r2 + c)
		if(c >= 10):
			carry += 1
			c = 1
		else:
			c = 0
			
		temp1 = temp1 / 10
		temp2 = temp2 / 10   
		
	if(carry == 0):
		print('No carry operation')
	elif(carry == 1):
		print(str(carry) + " carry operation")
	else:
		print(str(carry) + " carry operations")       


t=eval(input())
while t>0:
	t-=1
	n1,n2=list(map(int,input().split()))
	c=0
	while (n1%10) and (n2%10):
    		a= n1%10
    		b= n2%10
    		if (a+b>9):
        		c+=1
    		n1/=10
    		n2/=10
	if c==0:
	    print("No carry operation")
	elif c==1:
    		print("1 carry operation")
	else:
    		print("{0} carry operations".format(c))