Advertisement
Guest User

Untitled

a guest
Oct 4th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <algorithm>
  5. #include <ctype.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. string line;
  14. getline (cin, line);
  15.  
  16. int sum = 0;
  17.  
  18. istringstream element (line);
  19.  
  20. string current;
  21. string output;
  22.  
  23. while (element >> current)
  24. {
  25.  
  26.     if (isdigit(current[0]) || current [0] == '-')
  27.     {
  28.         int num = stoi (current);
  29.         sum += num;
  30.     } else
  31.     {
  32.         output += current + " ";
  33.     }
  34. }
  35.  
  36. cout << sum << endl;
  37. cout << output << endl;
  38.  
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement