forked from omonimus1/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess-a-string.cpp
More file actions
45 lines (36 loc) · 841 Bytes
/
process-a-string.cpp
File metadata and controls
45 lines (36 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// https://www.codechef.com/problems/KOL15A
#include <bits/stdc++.h>
using namespace std;
int get_sum_digits(string word)
{
// Case 1 : string is empty
if(word.size() == 0)
return 0;
// Case 2: string is NOT empty
int sum = 0;
for(int i=0; i < word.size(); i++)
{
cout << "sum is: "<<sum<<endl;
cout << "single char: "<<word[i]<<endl;
if(isdigit(word[i]))
{
// 49: is the ASCI Value of 1
sum += (int)word[i] - 48;
}
}
return sum;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test_cases;
cin >> test_cases;
string word;
while(test_cases--)
{
cin >> word;
cout << get_sum_digits(word)<<endl;
}
return 0;
}