SAP interview question

Write a program to add numbers present in a String , example : Gl123a45ssd908oo6r, so the program should give 123 + 45 + 908 + 6 = 1082 as the result. There were 2 more programming questions related to stacks and linkedlists and one question on probability followed by a logical puzzle question.

Interview Answers

Anonymous

1 Jun 2020

import re result = re.sub("[A-z]"," ",input) res = result.split(" ") sum=0 for i in res: if not i == "": sum+=int(i) input = input()

2

Anonymous

24 Jun 2020

str=input() temp=0 sum=0 for i in str: if(i.isdigit()): temp=(temp*10)+int(i) else: sum=sum+temp temp=0 print(sum)

Anonymous

31 May 2020

def findSum(str1): temp = "0" Sum = 0 for ch in str1: if (ch.isdigit()): temp += ch else: Sum += int(temp) temp = "0" return Sum + int(temp) str1 = "Gl123a45ssd908oo6r" print(findSum(str1))

1