nicuvlad76

Untitled

Mar 8th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char s[60];
  5. long long st[60];
  6. int top;
  7.  
  8. inline int Cifra(char ch)
  9. {
  10. return ('0' <= ch && ch <= '9');
  11. }
  12.  
  13. int main()
  14. {
  15. int i, semn = 1, op = 0;
  16. long long suma, x;
  17. cin >> s;
  18. for (i = 0; s[i]; )
  19. if (!Cifra(s[i]))
  20. {
  21. if (s[i] == '-') semn = -1;
  22. else semn = 1;
  23. if (s[i] == '*') op = 1;
  24. else op = 0;
  25. i++;
  26. }
  27. else
  28. {
  29. x = 0;
  30. while ('0' <= s[i] && s[i] <= '9')
  31. {
  32. x = x * 10 + s[i] - '0';
  33. i++;
  34. }
  35. x *= semn;
  36. if (op == 1) st[top] = st[top] * x;
  37. else st[++top] = x;
  38. semn = 1;
  39. op = 0;
  40. }
  41. suma = 0;
  42. for (i = 1; i <= top; i++)
  43. suma += st[i];
  44. cout << suma << "\n";
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment