+ 3

Would you solve in Python ?

Input: A string of comma separated numbers ,the numbers 5 and 8 are present in the list(8 always comes after 5 Num1 : Add all members which do not lie between 5 and 8(excluding 5,8) Num2: Number form by concanatic all numbers from 5 to 8(including 5,8) Output Num1+num2 Case 1: Input =3,2,6,5,1,4,8,9 Output=5168 num1=3+2+6+9=20 num2='5'+'1'+'4'+'8'=5148 Output=5148+20=5168 Case 2: Input:=3,1,5,8 Output =62

16th May 2020, 4:14 PM
अभि
अभि - avatar
6 odpowiedzi
+ 3
so 1,2,5,3,8,4 make 1+2+4 as num1 and 538 as num2 with result 7+538 =545 try a fsm with two states out within start = before 5 changes state to within 8 changes state to out now iterate the string, ignore comma and perform the elements according to state.
16th May 2020, 4:53 PM
Oma Falk
Oma Falk - avatar
16th May 2020, 4:58 PM
Oma Falk
Oma Falk - avatar
+ 1
Your question still isn't clear ,what does it means to add numbers that do not lie between 5 and 8? That's literally infinite numbers Maybe give a sample input and output as well or show what you attempted so far ,so we could further help
16th May 2020, 4:19 PM
Abhay
Abhay - avatar
0
Need more info....(so we can code it and point you in the right direction):- Would your input contain repeated numbers?
16th May 2020, 5:22 PM
rodwynnejones
rodwynnejones - avatar
18th May 2020, 9:38 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
inp = "3,2,6,5,1,4,8,9" #inp = "3,1,5,8" nums = inp.split(',') # -------------------------------- # calculating num1 num1=0 for i in nums: i = int(i) if i==5: break num1 += i for j in nums[::-1]: j = int(j) if j==8: break num1 += j # -------------------------------- # calculating num1 num2="" for k in range(inp.find('5'), inp.find('8')+1): if inp[k].isdigit(): num2 += str(inp[k]) print num1 + int(num2)
19th May 2020, 12:49 AM
Ahmed Muhammed
Ahmed Muhammed - avatar