Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. unsigned int k = 0, cnt = 0;
  8.  
  9. int F(string s, int iter);
  10.  
  11. int main()
  12. {
  13. string str;
  14. unsigned int sumPos = 0;
  15. getline(cin, str);
  16. while (k < str.length())
  17. {
  18. if (isdigit(str[k]))
  19. sumPos += F(str, k);
  20. else
  21. k++;
  22. }
  23. cout << sumPos;
  24. return 0;
  25.  
  26. }
  27.  
  28.  
  29. int F(string s, int iter)
  30. {
  31. string sLoc = "";
  32. int pos = 0,sumLoc;
  33. int sign = 1;
  34. if ((s[k - 1] == '-') && (k >= 1))
  35. sign *= -1;
  36. while (isdigit(s[iter]))
  37. {
  38. sLoc += s[iter];
  39. iter++;
  40. pos++;
  41. }
  42. k += pos;
  43. char* str = new char[pos];
  44. sumLoc = atoi(sLoc.c_str());
  45. return sign * sumLoc;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement