Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <sstream>
- using namespace std;
- int main() {
- string line;
- getline(cin, line);
- istringstream input(line);
- int val, sum = 0, count = 0;
- vector<char> v;
- char ch;
- while(input >> ch) {
- v.push_back(ch);
- // cout << ch << " ";
- }
- for(int i = 0 ; i < v.size() ; ++i)
- {
- if(isalpha(v[i])) {
- cout << "Invalid Input" << endl;
- return 0;
- //sum += (v[i] - '0');
- }
- else{
- sum += (v[i] - '0');
- }
- }
- cout << sum << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment