Solution for Equation Solver in C++


May 6, 2020 0.120532 seconds C++
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int total = 0;
	string inp = "";
	cin >> total;
	cin >> inp;
	while(inp != "="){
		if(inp == "P"){
			cin >> inp;
			if(inp == "=") break;
			total += stoi(inp);
		}else{
			cin >> inp;
			if(inp == "=") break;
			total -= stoi(inp);
		}
		cin >> inp;
	}
	cout << total << "\n";
	return 0;
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.