Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <queue>
- #include <sstream>
- using namespace std;
- int main() {
- string line, s;
- getline(cin, line);
- istringstream ss(line);
- queue<int> numbers;
- queue<string> expressions;
- int counter = 0;
- while (ss >> s) {
- if (counter % 2 == 0) {
- numbers.push(stoi(s));
- }
- else {
- expressions.push(s);
- }
- counter++;
- }
- int sum = numbers.front();
- numbers.pop();
- while (!expressions.empty()) {
- if (expressions.front() == "+") {
- sum += numbers.front();
- }
- else {
- sum -= numbers.front();
- }
- expressions.pop();
- numbers.pop();
- }
- while (!numbers.empty()) {
- sum += numbers.front();
- numbers.pop();
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement