Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- int SumNumbers(const std::string&);
- int main()
- {
- std::string s;
- std::cin >> s;
- std::cout << SumNumbers(s) << std::endl;
- return 0;
- }
- int SumNumbers(const std::string& s)
- {
- int sum = 0;
- for (char ch : s)
- if (std::isdigit(ch))
- sum += ch - '0';
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement