Author- [Virender Yadav]
Tester- [Vipin Khushu]
Editorialist- [Virender Yadav]
We have given a string of numbers and words . Our task is to find sum of all number in the string.
As the size of string is 10^5.
So the most biggest size of integer can be of length 10^5 , we have to use array to store integer value inside string.
Take two array b,c of size equal to length of given string a. One to store an integer at any place in string and second to store sum.
The concept behinde this is that store first integer inside string in an array b and sum it with array c and empty array b, so the sum gets stored in c and now store next integer in b.
Traverse a loop in string a, check if a[i] is in an integer so put it in array b at last position and if in next time when i increments a[i] is an integer put that in second last position else sum both array b and c and empty array b.
Sum array b and c once again at the end of loop because if the last element is integer it also gets in sum.
Now check if the array C is with 0 or empty if empty print “-1” else print the sum stored inside it.