Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- string command;
- cin >> command;
- vector<int> numbers;
- while (command != "end") {
- if (command == "sum") {
- numbers[numbers.size() - 2] += numbers[numbers.size() - 1];
- numbers.pop_back();
- }
- else if (command == "subtract") {
- numbers[numbers.size() - 1] -= numbers[numbers.size() - 2];
- numbers.erase(numbers.begin() + numbers.size() - 2);
- }
- else if (command == "concat") {
- numbers[numbers.size() - 2] = stoi(to_string(numbers[numbers.size() - 2]) + to_string(numbers[numbers.size() - 1]));
- numbers.pop_back();
- }
- else if (command == "discard") {
- numbers.pop_back();
- }
- else {
- numbers.push_back(stoi(command));
- }
- cin >> command;
- }
- for (auto& n : numbers) {
- cout << n << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement