count-carry-problem-3

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:
n=int(input())
s=""
for i in range(0,n):
	s=input().split(" ")
	a=s[0]
	b=s[1]
	cnt=0
	for j in range(0,len(a)):
		if((int(a[j])+int(b[j]))>9):
			cnt=cnt+1
	if(cnt==0):
		print('No carry operation')
	elif(cnt==1):
		print(cnt,'carry operation')
	else:
		print(cnt,'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))


n=int(input())
for j in range(n):
	n,k=input().split()
	n=list(n)
	n=list(map(int,n))
	k=list(k)
	k=list(map(int,k))
	s=min(len(n),len(k))
	i=s-1
	carry=0
	while i>=0:
		m=n[i]+k[i]
		if m>=10 and i!=0:
			carry+=1
			n[i-1]+=1
		elif m>=10:
			carry+=1
		m=0
		i-=1
	if carry==0:
		print("No carry operation")
	elif carry==1:
		print("1 carry operation")
	else:
		print("%s carry operations" % carry)


#[R][C]
#step1:Input of Number of test cases
#step2:Input of each test cases
#step3:Divide then in two arrays of num
#step4:sum each numbers and store in a third array
#step5:Loop no bits in the less no
#step6:If each bit of result is less than any of that corresponding no.s then no carry

def main():
#step1:Input of test cases
	testCase = eval(input())
#step2:Input of each test cases
	for i in range(0,testCase):
		NK=input()
		NK=NK.split()
		
		N1=list(NK[0])
		N2=list(NK[1])
		
		R1=int(NK[0])
		R2=int(NK[1])
		
		R1=R1+R2
		R1=str(R1)
		R=list(R1)

		l=0
		ln1=len(N1)
		ln2=len(N2)
		lR=len(R)

		if int(NK[0])>int(NK[1]):
			l=len(N2)
		else:
			l=len(N1)
		c=0
		for i in range(0,l):
			if (int(R[lR-i-1])<int(N1[ln1-i-1])) or (int(R[lR-i-1])<int(N2[ln2-i-1])):
				c=c+1
		
				
		if c==0:
			print('No carry operation')
		elif c==1:
			print('1 carry operation')
		else:
			print(c,'carry operations')
			
				
if __name__ == "__main__":
	main()


for i in range(int(input())):
	a=input().split();
	x=a[0]
	y=a[1]
	r=0
	for j in range(len(x)):
		a1=int(x[j])
		a2=int(y[j])
		if(a1+a2>9):
			r=r+1
	if(r==0):
		print("No carry operation")
	elif(r==1):
		print("1 carry operation")
	else:
		print(str(r)+" carry operations")


cases = int(input())

for case in range(cases):
	m, n = [int(i) for i in input().split(' ')]
	carry = 0
	c_count = 0
	
	while m!=0 or n!=0:
		a = m%10
		b = n%10
		if a+b+carry>9:
			c_count += 1
			carry = 1
		else:
			carry = 0
		
		m /= 10
		n /= 10
	
	if c_count==0:
		print("No carry operation")
	elif c_count==1:
		print("1 carry operation")
	else:
		print(str(c_count) + " carry operations")
	


a=eval(input())
for i in range(a):
	b=input()
	c=b.split(" ")
	d= (c[0])
	e= (c[1])
	num1=[]
	num2=[]
	for i in range(len(d)):
		num1.append(int(d[i]))
	for j in range(len(e)):
		num2.append(int(e[j]))
	count = 0
	for k in range(len(num1)-1):
		if (num1[k]+num2[k])>=10:
			count +=1
			num1[k+1]+=1
	if num1[len(num1)-1]+num2[len(num2)-1]>=10:
		count +=1
	if count==0:
		print("No carry operation")
	elif count==1:
		print(str(count)+" carry operation")
	else:
		print(str(count)+" carry operations")
	
	


t = int(input())
while t>0:
	a,b = [int(i) for i in input().split()]
	cnt = 0
	while a and b:
		if a%10 + b%10 >9:
			cnt+=1
		a=a//10
		b=b//10
	if cnt == 0:
		print('No carry operation')
	elif cnt == 1:
		print('%d carry operation'%(cnt))
	else:
		print('%d carry operations'%(cnt))
	t-=1


def answer(inp_list):
	num_1, num_2 = int(inp_list[0]), int(inp_list[1])
	
	carry_count = 0
	carry = 0
	
	while(num_1 > 0 or num_2 > 0):
		unit_num_1, unit_num_2 = num_1 % 10, num_2 %10
		num_1, num_2 = num_1 / 10, num_2 / 10
		carry = (unit_num_1 + unit_num_2 + carry) / 10
		if(carry > 0):
			carry_count += 1
	
	return carry_count


for t in range(int(input())):
	ans = answer(input().split(' '))
	if(ans == 0):
		print("No carry operation")
	elif(ans == 1):
		print(ans, "carry operation")
	else:
		print(ans, "carry operations")


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=eval(input())
for tt in range(t):
	cry=0
	a,b=input().split()
	m=max(len(a),len(b))+1
	a='0'*(m-len(a))+a
	b='0'*(m-len(b))+b
	cr=0
	for mm in range(m):
		ad,bd=list(map(int,[a[mm],b[mm]]))
		su=ad+bd+cr
		if su>9:
			cry+=1
			cr=su-9
	if cry==0:
		print("No carry operation")
	elif cry==1:
		print("1 carry operation")		
	else:
		print(cry,"carry operations")