Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. Then T test cases follow.
Each test case is described with a single line containing a string S, the alphanumeric string.

------ Output ------ 

For each test case, output a single line containing the sum of all the digit characters in that string.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ |S| ≤ 1000, where |S| is the length of the string S.$

----- Sample Input 1 ------ 
1
ab1231da

----- Sample Output 1 ------ 
7
----- explanation 1 ------ 
The digits in this string are 1, 2, 3 and 1. Hence, the sum of all of them is 7.

Difficulty: EASY
Tags: Constructive algorithms

String algorithms

Mathematics

Data structures

Ad-hoc
Skill types: Data structures

Starter code:

Solutions:
test = int(input())
for i in range(test):
	sum = 0
	s = input()
	for j in s:
		if j.isdigit():
			sum = sum + int(j)
		else:
			pass
	print(sum)


for _ in range(int(input())):
	a = input()
	b = []
	for i in a:
		if i.isdigit():
			b.append(int(i))
	print(sum(b))


n = int(input())
for i in range(n):
	l = []
	s = input()
	for j in s:
		if j.isnumeric():
			l.append(int(j))
	print(sum(l))


t = int(input())
for i in range(t):
	s = input()
	new_arr = []
	for x in s:
		if x.isdigit():
			new_arr.append(int(x))
	print(sum(new_arr))


for _ in range(int(input())):
	s = input()
	x = [i for i in s]
	k = []
	for j in x:
		if j.isdigit():
			k.append(j)
	res = [round(float(i)) for i in k]
	print(sum(res))


for _ in range(int(input())):
	s = input()
	res = 0
	for i in s:
		if i.isnumeric():
			res += int(i)
	print(res)


t = int(input())
for i in range(t):
	n = input()
	l = 0
	for i in n:
		if i.isnumeric():
			l = l + int(i)
	print(l)


t = int(input())
for t in range(t):
	s = input()
	su = 0
	for i in s:
		if i.isdigit():
			su = su + int(i)
	print(su)


def sum(s):
	sum = 0
	for i in s:
		if i.isdigit():
			sum += int(i)
	return sum
for i in range(int(input())):
	s = input()
	print(sum(s))


n = int(input())
while n != 0:
	x = input()
	c = 0
	for i in range(0, len(x)):
		if x[i].isdigit() == True:
			k = int(x[i])
			c = c + k
	print(c)
	n = n - 1


t = int(input())
for i in range(t):
	s = input()
	sum = 0
	for i in range(len(s)):
		if ord(s[i]) >= 48 and ord(s[i]) <= 57:
			sum = sum + int(s[i])
	print(sum)


for i in range(int(input())):
	c = 0
	s = input()
	for i in s:
		if i.isdigit():
			c += int(i)
	print(c)


n = int(input())
for i in range(n):
	k = input()
	c = 0
	for i in k:
		if i.isdigit():
			c += int(i)
	print(c)


for i in range(int(input())):
	s1 = input()
	s = 0
	for i in s1:
		if i.isdigit():
			p = int(i)
			s = s + p
	print(s)


for i in range(int(input())):
	a = input()
	b = '0123456789'
	c = 0
	for i in range(len(a)):
		if a[i] in b:
			c = c + int(a[i])
	print(c)


T = int(input())
for k in range(T):
	arr1 = []
	arr = list(map(str, input().strip()))
	for item in arr:
		if item.isdigit() == True:
			x = int(item)
			arr1.append(x)
	print(sum(arr1))


s = int(input())
for i in range(s):
	a = input()
	count = 0
	for j in range(len(a)):
		if a[j] in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
			count = count + int(a[j])
	print(count)


t = int(input())
for i in range(t):
	s = input()
	v = [x for x in s]
	k = []
	for z in v:
		if z.isdigit():
			k.append(int(z))
	print(sum(k))


for _ in range(int(input())):
	s = input()
	a = '123456789'
	c = 0
	for i in s:
		if i in a:
			c += int(i)
	print(c)


n = int(input())
for i in range(n):
	a = input()
	c = 0
	for j in a:
		if j.isdigit():
			c += int(j)
	print(c)


for _ in range(int(input())):
	s = str(input())
	t = 0
	for i in s:
		if i.isdigit():
			t = t + int(i)
	print(t)


for i in range(int(input())):
	sum = 0
	s = input()
	k = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	for i in s:
		if i not in k:
			sum = sum + int(i)
	print(sum)


t = int(input())
for i in range(t):
	s = input()
	c = 0
	for i in s:
		if i.isnumeric():
			c = c + int(i)
		else:
			continue
	print(c)


for t in range(int(input())):
	s = list(input())
	digits = [int(symbol) for symbol in s if symbol.isnumeric()]
	alphas = [symbol for symbol in s if not symbol.isnumeric()]
	print(sum(digits))


t = int(input())
for i in range(t):
	st = input()
	sm = 0
	for j in st:
		if j.isnumeric():
			sm = sm + int(j)
	print(sm)


for _ in range(int(input())):
	s = input()
	x = [int(s[i]) for i in range(len(s)) if s[i].isnumeric()]
	print(sum(x))


t = int(input())
for _ in range(t):
	s = input()
	c = 0
	for i in s:
		if i.isdigit() == True:
			c = c + int(i)
	print(c)


t = int(input())
for i in range(t):
	s = input()
	a = '123456789'
	count = 0
	for i in s:
		if i in a:
			i = int(i)
			count += i
	print(count)


for i in range(int(input())):
	Strs = input()
	tot = 0
	for i in Strs:
		if ord(i) < 97:
			tot += int(i)
	print(tot)


for i in range(int(input())):
	s = input()
	l = []
	n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
	for i in s:
		if i in n:
			l.append(i)
	res = 0
	for i in l:
		res = res + int(i)
	print(res)


for i in range(int(input())):
	x = input()
	n = '123456789'
	c = 0
	for i in x:
		if i in n:
			i = int(i)
			c = c + i
	print(c)


for i in range(int(input())):
	s = input()
	c = 0
	for i in range(len(s)):
		a = s[i]
		if a.isdigit() == True:
			b = int(a)
			c = c + b
	print(c)


for _ in range(int(input())):
	string = list(str(input()))
	lst = []
	for i in string:
		if i in 'abcdefghijklmnopqrstuvwxyz':
			pass
		else:
			lst.append(int(i))
	print(sum(lst))


for _ in range(int(input())):
	s = str(input())
	sum1 = 0
	for i in s:
		if i.isnumeric() == True:
			sum1 += int(i)
	print(sum1)


n = int(input())
for i in range(n):
	s = input()
	l1 = []
	for i in s:
		if i.isdigit():
			l1.append(i)
	l1 = list(map(int, l1))
	print(sum(l1))


for _ in range(int(input())):
	s = input()
	sum = 0
	for i in s:
		if i.isdigit():
			sum += int(i)
	print(sum)


for _ in range(int(input())):
	s = input()
	d = '0123456789'
	suma = 0
	i = 0
	while i < len(s):
		if s[i] in d:
			suma += int(s[i])
		i += 1
	print(suma)


for _ in range(int(input())):
	test_string = input()
	sum = 0
	for x in test_string:
		if x.isdigit():
			sum += int(x)
	print(sum)


T = int(input())
for i in range(T):
	s = input()
	nums = '0123456789'
	sum = 0
	for i in s:
		if i in nums:
			sum += int(i)
	print(sum)


t = int(input())
for i in range(t):
	lst = list(input())
	ans = 0
	for j in lst:
		if j.isalpha():
			continue
		else:
			ans += int(j)
	print(ans)


for i in range(int(input())):
	b = input()
	sum = 0
	for i in b:
		if i.isdigit():
			sum += int(i)
	print(sum)


goals = int(input())
for distractions in range(goals):
	wife = input()
	stress = [i for i in wife]
	life = []
	for j in stress:
		if j.isdigit():
			life.append(j)
	aim = [round(float(i)) for i in life]
	print(sum(aim))


for _ in range(int(input())):
	s1 = input()
	s = 0
	for i in s1:
		if i in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'):
			s = s + int(i)
	print(s)


t = int(input())
for _ in range(t):
	s = input()
	val = 0
	for i in range(len(s)):
		if s[i] >= '1' and s[i] <= '9':
			val += int(s[i])
	print(val)


import re
for i in range(int(input())):
	s = input()
	res = re.sub('[a-zA-Z]', '', s)
	c = 0
	for i in range(len(res)):
		c += int(res[i])
	print(c)


for _ in range(int(input())):
	s = input()
	sk = []
	for i in s:
		if '0' <= i <= '9':
			sk.append(int(i))
	print(sum(sk))


t = int(input())
for i in range(t):
	s = input()
	t = 0
	for i in range(len(s)):
		if s[i].isnumeric():
			t += int(s[i])
	print(t)


t = int(input())
for i in range(t):
	s = input()
	ans = 0
	for ch in s:
		if ord(ch) >= 48 and ord(ch) <= 57:
			ans += ord(ch) - 48
	print(ans)


import re
t = int(input())
for i in range(t):
	s = list(input())
	res = []
	for i in s:
		if i.isdigit():
			res.append(i)
	su = 0
	for k in range(len(res)):
		su += int(res[k])
	print(su)


t = int(input())
for i in range(t):
	n = input()
	d = 0
	for i in n:
		if i == '1' or i == '2' or i == '3' or (i == '4') or (i == '5') or (i == '6') or (i == '7') or (i == '8') or (i == '9') or (i == '0'):
			d = d + int(i)
	print(d)


t = int(input())
for i in range(t):
	s = list(input())
	s1 = []
	s3 = []
	l = '0123456789'
	for i in range(len(s)):
		if s[i] in l:
			s1.append(s[i])
	s2 = [int(x) for x in s1]
	print(sum(s2))


t = int(input())
val = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(t):
	s = input()
	ans = 0
	for i in range(len(s)):
		if s[i] not in val:
			ans += int(s[i])
	print(ans)


for i in range(int(input())):
	s = input()
	num = '123456789'
	sum = 0
	for n in num:
		for str in s:
			if n == str:
				sum += int(n)
	print(sum)


for i in range(int(input())):
	s = 0
	for j in input():
		if ord(j) >= 48 and ord(j) <= 57:
			s = s + int(j)
	print(s)


t = int(input())
for test in range(t):
	s = input()
	a = 0
	for i in s:
		if i.isnumeric():
			a += int(i)
	print(a)


for _ in range(int(input())):
	a = input()
	b = []
	for i in a:
		if not i.isalpha():
			b.append(int(i))
	print(sum(b))


T = int(input())
for i in range(T):
	x = input()
	sum = 0
	for j in x:
		if j.isdigit():
			sum = sum + int(j)
	print(sum)


t = int(input())
for _ in range(t):
	s = input()
	count = 0
	for i in range(len(s)):
		if s[i] > '0' and s[i] <= '9':
			count += int(s[i])
	print(count)


for i in range(int(input())):
	s = input()
	sum1 = 0
	for i in s:
		if i.isdigit():
			sum1 = sum1 + int(i)
	print(sum1)


for i in range(int(input())):
	x = str(input())
	c = 0
	for i in x:
		if i == '1' or i == '2' or i == '3' or (i == '4') or (i == '5') or (i == '6') or (i == '7') or (i == '8') or (i == '9'):
			c = c + int(i)
		else:
			continue
	print(c)


times = int(input())
for time in range(times):
	alphanumeric = input()
	number = 0
	for i in alphanumeric:
		if i.isdigit() == True:
			number += int(i)
	print(number)


cases = int(input())
for _ in range(cases):
	s = input()
	ans = 0
	for i in s:
		if i.isnumeric():
			ans = ans + int(i)
	print(ans)


for i in range(int(input())):
	s = input()
	out = 0
	for i in s:
		if i.isdigit():
			out += int(i)
	print(out)


for i in range(int(input())):
	S = input()
	sum = 0
	for j in S:
		c = ord(j)
		if 48 <= c <= 57:
			sum += int(j)
	print(sum)


for i in range(int(input())):
	s = input()
	res = 0
	for i in s:
		if i.isdigit():
			res += int(i)
	print(res)